March 2018
Intermediate to advanced
324 pages
8h 30m
English
Both JUnit and TestNG use the @Test annotation to specify which method is considered to be a test. Unlike JUnit, which requires every method to be annotated with @Test, TestNG allows us to use this annotation on a class level, as well. When used in this way, all public methods are considered tests unless specified otherwise:
@Test
public class DirectionSpec { public void whenGetFromShortNameNThenReturnDirectionN() {
Direction direction = Direction.getFromShortName('N');
assertEquals(direction, Direction.NORTH);
} public void whenGetFromShortNameWThenReturnDirectionW() {
Direction direction = Direction.getFromShortName('W');
assertEquals(direction, Direction.WEST);
}
}
In this example, we put the @Test annotation above ...
Read now
Unlock full access