October 2017
Intermediate to advanced
442 pages
12h 33m
English
Some test technology also support crafting maintainable tests. AssertJ, for example, provides the possibility to create custom assertions. In our test case the car needs to verify the correct engine and color encapsulated into car specifications. Custom assertions can decrease overall duplication in the test scope.
The following shows a custom AssertJ assertion for verifying a car:
import org.assertj.core.api.AbstractAssert;
public class CarAssert extends AbstractAssert<CarAssert, Car> {
public CarAssert(Car actual) {
super(actual, CarAssert.class);
}
public static CarAssert assertThat(Car actual) {
return new CarAssert(actual);
}
public CarAssert isEnvironmentalFriendly() { isNotNull(); if (actual.getSpecification().getEngine() ...Read now
Unlock full access