O'Reilly logo

Java 9 Cookbook by Nick Samoylov, Mohamed Sanaulla

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

How it works...

Equipped with some knowledge of the JUnit framework, we can now write a real test method for the main case: the calculation of the speed of a vehicle of certain weight with an engine of certain horsepower to determine where it can reach in a certain period of time. We take the formula we used for writing the code (provided originally by the domain expert) and calculate the expected value. For example, if the vehicle has an engine of 246 hp and weight of 4,000 lb, then in 10 sec, its speed can reach 117 mph. Since the speed is of the type double, we will use this assertion:  

void assertEquals(String message, double expected,                        double actual, double delta)

Here, delta is allowable precision (we decided that 1 percent is good ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required