Details

Recommendation type: Exceptions and assertion errors

Configurable in Preferences: No

Filter category: Exceptions / assertion errors

Description

UTA displays this recommendation when:

Depending on you code, the following action links may be available:

(info) UTA does not show the Mark as expected and Remove expected exception options for tests that use @Rule ExpectedException to handle exceptions.

Examples for JUnit 4 Tests

Example 1 - Exception Thrown

The following test has been created for the makePayment method:

UTA detected that the exception was thrown:

Click Mark as expected to update @Test(expected=...) annotation with the exception that was thrown:

Example 2 - Expected Exception is Not Thrown

In the following example, IllegalArgumentException is expected:

UTA detected that no exception was thrown:

Click Remove expected exception to remove the Test(expected = IllegalArgumentException.class) annotation from the test:

Example 3 - Wrong Exception Thrown

In the following example, IllegalArgumentException is expected:

UTA detected that the exception that was actually thrown is Error:

Click Mark as expected to update @Test(expected=...) annotation with the exception that was thrown:

Examples for JUnit 5 Test

The following test has been created for the makePayment method:

UTA detected that the exception was thrown:

Click Mark as expected to wrap the exception that was thrown with the assertThrows method: