how to test that a method throws an exception junit5 [duplicate]
how to test that a method throws an exception junit5 [duplicate] This question already has an answer here: I have a DocumentTypeDetector class that has a detectForRequest() method. I'm doing the corresponding tests, but I have not been able to verify that a customized exception is thrown, I'm using JUNIT 5. DocumentTypeDetector detectForRequest() I have reviewed here, but the answers have not helped me, this is the code I have written following an example: @Test public void tryThrowExceptionForInvalidRequest() throws Exception{ InvalidInputRequestType exceptionThrown = Assertions.assertThrows( InvalidInputRequestType.class, () -> { throw new InvalidInputRequestType("La petición debe estar en un formato valido JSON o XML"); } ); assertEquals("La petición debe estar en un formato valido JSON o XML", exceptionThrown.getMessage()); } But this does not tell me anything about my test I need to ve...