Skip to content

Commit

Permalink
Add a link to assertThrows in exception testing
Browse files Browse the repository at this point in the history
Provide information about alternatives to the expected parameter which
can be used to overcome the limitations of expected.

This is an improvement for JUnit 4.13 to the fix for #806
(84dcb64).
  • Loading branch information
stefanbirkner authored and marcphilipp committed Oct 11, 2020
1 parent 543905d commit 1d17486
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/main/java/org/junit/Test.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.junit;

import org.junit.function.ThrowingRunnable;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
Expand Down Expand Up @@ -37,8 +39,16 @@
* new ArrayList<Object>().get(1);
* }
* </pre>
* If the exception's message or one of its properties should be verified, the
* {@link org.junit.rules.ExpectedException ExpectedException} rule can be used. Further
*
* Using the parameter <code>expected</code> for exception testing comes with
* some limitations: only the exception's type can be checked and it is not
* possible to precisely specify the code that throws the exception. Therefore
* JUnit 4 has improved its support for exception testing with
* {@link Assert#assertThrows(Class, ThrowingRunnable)} and the
* {@link org.junit.rules.ExpectedException ExpectedException} rule.
* With <code>assertThrows</code> the code that throws the exception can be
* precisely specified. If the exception's message or one of its properties
* should be verified, the <code>ExpectedException</code> rule can be used. Further
* information about exception testing can be found at the
* <a href="https://github.com/junit-team/junit4/wiki/Exception-testing">JUnit Wiki</a>.
*
Expand Down

0 comments on commit 1d17486

Please sign in to comment.