What else is new?
In addition to the important changes discussed so far, JUnit 4 also has introduced a few minor ones; namely the addition of a new assert method and the elimination of a terminal state.
JUnit 4 has added a new assert method for comparing array contents. It isn't a big addition, but it does mean you'll never again have to iterate over the contents of an array and assert each individual item.
For example, the code in Listing 22 isn't possible in older versions of JUnit. This test case fails because of the slight difference in the second element of each array.
Listing 22. assertEquals supports arrays now in JUnit 4
@Test
public void verifyArrayContents() throws Exception{
String[] actual = new String[] {"JUnit 3.8.x", "JUnit 4", "TestNG"};
String[] var = new String[] {"JUnit 3.8.x", "JUnit 4.1", "TestNG 5.5"};
assertEquals("the two arrays should not be equal", actual, var);
}
|
A small but sweet change in JUnit 4 is that it eliminates the notion of errors. Whereas previous versions would report both the number of failures and the number of errors, in JUnit 4, a test either passes or it fails.
Interestingly, while one state has been eliminated, a new one has been added, this time because of the ability to ignore tests. When you execute a series of tests, JUnit 4 reports the number of tests run, the number of failures, and the number of tests ignored.




