Java Reference
In-Depth Information
Listing 5.15. A JUnit test for the Greeting POJO
import static org.junit.Assert.*;
import org.junit.Test;
public class GreetingTests {
private Greeting greeting = new Greeting();
@Test
public void testGetGreeting() {
assertEquals("Hello, World!", greeting.getMessage());
}
@Test
public void testSetGreeting() {
greeting.setMessage("What up?");
assertEquals("What up?", greeting.getMessage());
}
}
ThenextlistingshowsaGradlebuildfilewithaJUnitdependencyduringthetestingphase.
It's still a “Hello, World” example, but it does introduce some essential concepts.
Listing 5.16. A build.gradle file for the POJO application with testing
The terms repositories and dependencies are part of the Gradle DSL. Any re-
quired libraries are listed in the dependencies block. There are several legal forms for
listing dependencies. The one used here is a string separated by colons. Using Maven syn-
tax is not an accident, as shown in the repositories section. Many different types of
repositories can be used, but here the standard Maven central repository is declared.
Executing the build this time runs the same series of tasks, but now any tests are executed
and a JUnit report in HTML form is produced in the build/reports/tests directory.
Search WWH ::




Custom Search