[英]How to Unit Test a method with a JavaFX Filechooser
How do i write a JUNIT test for a method that brings up a JavaFX Filechooser? 我该如何为启动JavaFX Filechooser的方法编写JUNIT测试? the unit test gets stuck awaiting for user input from that Filechooser
单元测试卡住,等待来自该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;
}
您可以为myController添加一个模拟,该模拟将实现相同的接口,但该模拟将仅返回文件路径,而无需任何用户干预。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.