Skip to content

Commit 1d17486

Browse files
stefanbirknermarcphilipp
authored andcommitted
Add a link to assertThrows in exception testing
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).
1 parent 543905d commit 1d17486

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/main/java/org/junit/Test.java

+12-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package org.junit;
22

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

0 commit comments

Comments
 (0)