Running Tests

To run the test case, right-click on FactorialTest.java and select Run As → JUnit Test. The JUnit view appears, and your tests are off and running. In this case, a red progress bar and a special icon next to the view title indicate that something went wrong (see Figure 22).

The JUnit view shows a summary of the last test run.

Figure 5-1. The JUnit view shows a summary of the last test run.

If you double-click on the test class or method name in the Failures list, Eclipse will open that test in the editor. Double-click on a line in the Failure Trace to go to a specific line number.

Tip

The best practice if a test fails is to set a breakpoint on the failing line and then use the debugger to diagnose the problem. Just select Debug instead of Run to run the debugger.

When you examine the test, you can see that the factorial function is not being calculated correctly, due to an error in the formula. To correct the error, replace the + with a *:

	           return x * factorial(x - 1);

Now, rerun your tests (Ctrl+F11). You shouldn't see any failures; instead, you should see a green bar, indicating success.

Get Eclipse IDE Pocket Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.