How do I assert my exception message with JUnit Test annotation?

前端 未结 12 2005
广开言路
广开言路 2020-12-12 08:53

I have written a few JUnit tests with @Test annotation. If my test method throws a checked exception and if I want to assert the message along with the exceptio

12条回答
  •  南方客
    南方客 (楼主)
    2020-12-12 09:18

    @Test (expectedExceptions = ValidationException.class, expectedExceptionsMessageRegExp = "This is not allowed")
    public void testInvalidValidation() throws Exception{
         //test code
    }
    

提交回复
热议问题