1
如何为调出JavaFX Filechooser的方法编写JUNIT测试? 单元测试卡从文件选择如何使用JavaFX Filechooser测试方法
@Test
public void testGetPath() {
try {
myController mc= new myController();
String s = uiController.getPath();
assertNotNull(s);
}
public String getPath() {
String s = "";
Task<Void> t = new Task<Void>() {
@Override
protected Void call() throws Exception {
FileChooser myFileChooser = new FileChooser ("/home/default");
File file = myFileChooser.showSaveDialog(appStage);
if (file != null) {
s = file.getAbsolutePath().toString();
}
}
};
Platform.runLater(t);
while (!t.isDone())
;
return s;
}