2014-05-21 38 views
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; 
} 

回答

0

你可以添加为一个myController的模拟这将实现相同的接口,但模仿只会返回一个文件路径,无须用户干预,等待用户输入。