まず、TreeView に特定のデータを入力できるアプリケーションを準備します (または現在のアプリをテスト モードをサポートするように変更します)。TreeView に偽のデータを提供するエンティティは、特定のデータのモックオブジェクトになります。TreeView の観点からはサービスのように見えるはずです。つまり、サービス クラスから共通のメソッドをインターフェイスに抽出し、TreeView が具体的なクラスの代わりにこのインターフェイスを使用するようにする必要があります。
UI テストを処理するには、JemmyFXライブラリを使用できます。TestView の UI プロパティを検証したり、マウス クリックやテキスト入力などのユーザー アクションを模倣したりする簡単なテストを作成できます。スレッドの問題について心配する必要はありません。jemmy が処理してくれます。
次のようになります (ここではテスト ハーネスとして junit を使用します)。
public class TreeTest {
@BeforeClass
public static void setUpClass() throws Exception {
// running your specially crafted FX application with mock service data
// you can do it any way, e.g. by calling main() method with some parameters
AppExecutor.executeNoBlock(TreeApp.class);
}
@Test // this is junit annotation for test
public void fooTest() {
// here we are receiving special jemmyfx entity which knows how to handle
// tree views and is attached to your TreeView
// (if you app has only one TreeView, you may need additional logic for several ones)
TreeViewDock tree = new TreeViewDock(new SceneDock().asParent());
// this way we can find some item which you expected to see in you TreeView
// because you've created you mock data this way.
// Note that underlying code will respect UI threading,
// will understand that UI can have delay and will give it certain time without blocking
// and will throw descriptive exception in case expected item wasn't found
tree.asTree().selector().select(new ByToStringLookup("item1"));
// you can find subitems
tree.asTree().selector().select(new ByToStringLookup("item1"), new ByToStringLookup("subitem1");
// and perform operations on them, e.g. expand:
new TreeItemDock(tree.asItemParent(), new EqualsLookup("item2")).asTreeItem().expand();
//etc
}
コード補完のヒントだけでサイトの詳細情報を見つけることができます