Details

Recommendation type: Exceptions and assertion errors

Configurable in Preferences: No

Filter category: Exceptions / assertion errors

Description

UTA displays this recommendation when:

  • a test fails during execution.
  • an unexpected exception is thrown (see Example 1).
  • an expected exception fails to be thrown (see Example 2).
  • the exception that is thrown is different than the expected exception (see Example 3).

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

  • Highlight - highlights the issue in the execution flow displayed in the Unit Test Assistant view.
  • Go to - highlights the code associated with the recommendation in the editor (for example, the code that throws the exception).
  • Mark as expected - marks the reported exception as expected by extending the test with the @Test(expected=...) annotation and prevents UTA from displaying this recommendation during subsequent test runs.
  • Remove expected exception - removes the @Test(expected=...) annotation from the test code; this option is available if the expected exception fails to be thrown during the test run.

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

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:


  • No labels