Recommendation type: Exceptions and assertion errors
Configurable in Preferences: No
Filter category: Exceptions / assertion errors
UTA displays this recommendation when:
Depending on your code, the following action links may be available:
@Test(expected=...) annotation (see Examples for JUnit 4 Tests).assertThrows() method (see Examples for JUnit 5 Tests).@Test(expected=...) annotation or the assertThrows() method from the test code; this option is available if the expected exception fails to be thrown during the test run.This feature depends on LLMs, which may produce inaccurate information. |
UTA does not show the Mark as expected and Remove expected exception options for tests that use
@Rule ExpectedException to handle exceptions.
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:

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:

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:

The following test has been created for the makePayment method:

UTA detected that the exception was thrown:

Click Fix with AI. The dialog displays output from the LLM provider with a suggestion on how to fix the test:

Click Apply Fix. A diff view of the code will open, allowing you to edit the code if needed before appending it to the test class:

Click Apply.
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:
