March 2018
Intermediate to advanced
208 pages
4h 52m
English
| | class DistanceConversionTest { |
| | |
| » | @Test |
| | void testConversionRoundTrip() { |
| | assertRoundTrip(1); |
| | assertRoundTrip(1_000); |
| | assertRoundTrip(9_999_999); |
| | } |
| | |
| » | private void assertRoundTrip(int kilometers) { |
| | Distance expectedDistance = new Distance( |
| | DistanceUnit.KILOMETERS, |
| | kilometers |
| | ); |
| | |
| | Distance actualDistance = expectedDistance |
| | .convertTo(DistanceUnit.MILES) |
| | .convertTo(DistanceUnit.KILOMETERS); |
| | |
| | Assertions.assertEquals(expectedDistance, actualDistance); |
| | } |
| | } |
Sometimes, you need to test a method or chain of methods in the same way, but with many different input parameters. That’s when you want to make sure that the method works for a large range of values. It’s easy to enumerate the parameters ...