In Java how can I validate a thrown exception with JUnit?

前端 未结 10 1192
甜味超标
甜味超标 2020-11-30 05:47

When writing unit tests for a Java API there may be circumstances where you want to perform more detailed validation of an exception. I.e. more than is offered by the @t

10条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-30 06:25

    i did something very simple

    testBla(){
        try {
            someFailingMethod()
            fail(); //method provided by junit
        } catch(Exception e) {
              //do nothing
        }
    }
    

提交回复
热议问题