Chapter 5. Unit Testing with JUnit

JUnit is a regression testing framework written by Kent Beck and Erich Gamma. Since Erich is the project leader for Eclipse's Java toolkit, it's only natural that JUnit is well integrated into the IDE.

A Simple Factorial Demo

To try out unit testing in Eclipse, first create a project called Factorial containing a class called Factorial. Inside that class, create a factorial() method as follows:

	           public class Factorial {
		public static double factorial(int x) {
			if (x == 0)
				return 1.0;
			return x + factorial(x - 1);
		}
	}

Tip

If you notice the nasty little error in this code, ignore it for now. That's part of the demonstration!

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.