Java Reference
In-Depth Information
Difference between errors and failures
As far as JU nit is concerned, encountering a runtime error or throwing an
uncaught exception inside a test is enough to fail a test. IDEA , however, differen-
tiates between these types of errors and a test method failing an assertion check.
As shown in table 7.2, different icons are assigned to differentiate these two dis-
tinct conditions and highlight the errors. Errors include runtime exceptions,
declared exceptions, and other problems: for instance, if a test case's class can't be
found or can't execute for some reason. In figure 7.4, you see a number of failed
test cases. In the Output window, it's easy to spot the problem—the rate returned
by the fixed rate service wasn't the rate that was expected.
This distinction between errors and failures can be important when you're
designing test cases. To take advantage of it, we suggest that you design your test
cases such that exceptions are thrown only when a problem that prevents run-
ning of the test is encountered, and that a legitimate failure is the result of
unsuccessful assertion. This strategy will allow you to more easily spot tests that
can't run properly due to configuration problems or other issues rather than a
true bug in your code.
Hiding the results of successful tests
Enabling the Hide Passed Tests option on the toolbar in the JU nit window alters
the test tree to show only the tests that failed or encountered errors, thus allowing
you to concentrate on the problems. This button is a toggle; you can toggle the
Figure 7.4 The JUnit tool window shows you the output from tests encountering both failures and
errors as you select them. Failures are distinguished from errors by their icons in the test tree.
 
 
 
Search WWH ::




Custom Search