TestNG: How to test for mandatory exceptions?

后端 未结 7 1737
刺人心
刺人心 2020-12-06 09:21

I\'d like to write a TestNG test to make sure an exception is thrown under a specific condition, and fail the test if the exception is not thrown. Is there an easy way to do

7条回答
  •  伪装坚强ぢ
    2020-12-06 10:12

    if you are using java 7 and testng this can be used for java 8 you can also use lambda expressions

    class A implements ThrowingRunnable{
    
    
                @Override
                public void run() throws AuthenticationFailedException{
                    spy.processAuthenticationResponse(mockRequest, mockResponse, authenticationContext);
                }
            }
            assertThrows(AuthenticationFailedException.class,new A());
    

提交回复
热议问题