May 2015
Intermediate to advanced
234 pages
4h 18m
English
JUnit, first released in 2000, is the most widely used Java unit testing framework. Eclipse supports it out of the box.
In this recipe, we will write and execute a JUnit 4 test.
In this recipe, we'll test this simple method (located in the NumberUtil class), which adds two integers:
public static int add(int a, int b) {
return a + b;
}Follow these steps to test a method with JUnit 4:
junit Maven dependency in pom.xml:<dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.10</version> <scope>test</scope> </dependency>
Read now
Unlock full access