开发者

Query regarding assert in JUnit

All,

I am having a hard time understanding the concept of assertXXX () in Junit. Currently, I have a method A(String fileName) that is generating a xml file for a input filename "XXX.XX" . So my test case includes testing if the code is generating any file and not just XML file which is wrong i.e. method A should only genera开发者_JAVA百科te xml files.

My code is:

testCreateFile()
{
     String fileName = "testFile.csv";
     A(fileName);
     File fileObj = new File (fileName);
     assertFalse(fileObj.exists()); // Since I check if the file should not be created

}

If I do this, I get an AssertionError and jUnit window shows 2 Failures. Do I have to handle this Exception?


if A creates a file, don't you want to assertTrue? In other words, you expect to find the file after you run A. And then you assert that the content of the file is the expected xml...

If an exception is a failure, you don't need to handle the exception.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜