March 2015
Beginner to intermediate
274 pages
6h 1m
English
Another weapon for our testing arsenal is better testing assertions. Have you noticed how sometimes stacktraces for failed tests are really unfriendly and/or mystically wrong? They give you little information about the real failure and you end up confused, having to read the entire source to fathom out how to fix the problem.
As an example, look at this assertion:
org.junit.Assert.assertEquals(3, myList.size());
We are asserting that a collection of objects after some task has a size of three, look at our error message when the test fails:
java.lang.AssertionError: Expected :3 Actual :2
Ok, that kind of makes sense, but it's a bit abstract. What item is missing from our list? I am going to have to run the tests again to find out, or ...
Read now
Unlock full access