我是 jUnit 的新手。无法弄清楚如何测试处理的异常。
public File inputProcessor(String filePath){
File file = null;
try {
file = new File(filePath);
Scanner input = new Scanner(file);
} catch (FileNotFoundException e) {
System.out.print("Check your input file path");
e.printStackTrace();
}
return file;
}
现在,想用无效的文件路径进行测试,以检查是否正确抛出和捕获异常。我写了这个
@Test (expected = java.io.FileNotFoundException.class)
public void Input_CheckOnInvalidPath_ExceptionThrown() {
Driver driver = new Driver();
String filePath = "wrong path";
File file = driver.inputProcessor(filePath);
}
但是因为我已经发现了我的异常,所以它不起作用。测试失败。任何帮助都会很棒!谢谢