Java Reference
In-Depth Information
In JUnit 3 tests extended the org.junit.TestCase class, and test methods were de-
tected by reflection. TestCase had all the needed assert methods in it. Now, in JUnit 4,
tests don't have a superclass and are detected through the @Test annotation. The assert
methods are now static methods in the Assert class, leading to probably the most com-
mon use of static imports in all of Java. If you do a static import on the Assert class you
can write the assert methods the same way they looked in the older version.
The only other interesting part of this is the use of the expected property of the @Test
annotation, which declares that the test only passes if the expected exception is thrown.
Figure 6.2 shows the result.
Search WWH ::




Custom Search