We haven't mentioned where JaCoCo fits in yet. JaCoCo is a test coverage tool. It monitors your system while it is being tested and can tell you which bits of your system were executed during the tests. NetBeans can show you the results by highlighting your code. This is a fairly crude way of quickly seeing where your tests are lacking --- code that isn't executed when the tests run is code that hasn't been tested.
Right click the root of your project in the <
> pane and select < Collect and Display Code Coverage">>.
Now take a look at your
Invoice class. You should see that some of the code is highlighted in green and some is red. The red bits are code that was not executed during the tests, and the green bits are the code that was. In this case the red bits are just simple getter methods, so we don't really care that we missed them in the tests.
<> All that JaCoCo (and other code coverage tools) is telling us about code that is green is that it was executed during the test run --- this doesn't mean that the code has actually been tested. You need to have appropriate
assert statements in the tests that check that the code is actually doing what it is supposed to be doing.
Basically, use code coverage tools to identify code that has been missed from tests --- but don't rely on the coverage percentages that they produce as a metric for test quality. You can get high coverage values by just calling each method in a class without using any assert statement to actually check anything. High coverage numbers do not mean quality tests.