Java Reference
In-Depth Information
cm = DistanceConverter.convertInchestoCm(inches);
assertEquals(25.4,cm,0.001);
}
}
11. Run the test case by clicking the green play icon or selecting Run, then Run. Ensure that no errors
or failures occur.
How It Works
Here's how it works:
1.
For each test method, a new method is being tested.
2.
You have supplied one value and the method calculates the second method.
3.
You find the expected value and enter this as one of the parameters in the assertEquals()
method.
4.
As long as the number you calculated and the number the method calculated are very close
(+/‐ epsilon ), the assertEquals() method will pass.
5.
If all eight tests pass, the testing is complete and all methods function as they are designed to.
6.
If there is a failure, you can use the Trace to find what went wrong. Is there a mistake in your
method or in your own calculation? This is up to you to figure out.
summary
This concludes the chapter on exceptions and debugging. The techniques you've seen in this chap-
ter should help you program with fewer errors and produce applications that function as expected.
Debugging, logging, and testing alone or in combination will not only help you accomplish this for
yourself, but will also demonstrate the correctness to others. When developing professionally, it is
not enough to know that your code works and why, but you need to be able to convince others (col-
leagues, clients, managers, and so on) that it works. As your programs get larger and more complex,
you will find these techniques more and more valuable.
 
Search WWH ::




Custom Search