Why won't this Expect Exception Junit Test Work?

前提是你 提交于 2019-12-02 09:14:10

Your test is failing because you are expecting the FileNotFoundException, but it not actualy thrown from a method. Why? Because of try/catch wrapper, that swallows the exception, only printing the stack trace to the output.

Change the catch block to

catch (FileNotFoundException e) {
            System.out.println("Error: Could not find database/storage.");
            System.out.println(e.getMessage()); 
            throw e;
            }

and test will pass

The issue is that your verifyUser(UserDataObject u, String filename) method catches both exceptions FileNotFoundException and IOException and hence it is not propagated to your test method.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!