What's the actual use of 'fail' in JUnit test case?

后端 未结 8 1205
长情又很酷
长情又很酷 2021-01-30 15:31

What\'s the actual use of \'fail\' in JUnit test case?

8条回答
  •  無奈伤痛
    2021-01-30 15:59

    Let's say you are writing a test case for a negative flow where the code being tested should raise an exception.

    try{
       bizMethod(badData);
       fail(); // FAIL when no exception is thrown
    } catch (BizException e) {
       assert(e.errorCode == THE_ERROR_CODE_U_R_LOOKING_FOR)
    }
    

提交回复
热议问题