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;
}