Published November 28, 2006 | https://doi.org/10.59350/gtt31-tee03

Code coverage: making sure your code is tested

Recently I discussed JUnit testing from within Eclipse , and blogged at several occasions about it in other situations. I cannot stress enough how useful unit testing is: it adds this extra set of eyeballs to make bugs shallow. And it does that, indeed.

Ensuring that you actually test all the code you write, however, is not easy. A couple of years back I read an article about Hansel, which does code coverage checking, but never got it nicely working for the CDK project. Never looked at that lately, so no idea how the current release would work out. Hansel is an extension of JUnit, and requires hard coding class names, which conflicts with CDK's module setup.

Thomas Kuhn pointed me last week to Emma, which seems a nice tool. It does not require hacking our source, and generates cool HTML:

And even highlights the source code:

BTW, I seem to be in good company: Classpath is using it too.

Below is the command I issued to generate the HTML output. Rajarshi, maybe this can be integrated into Nightly? Note that it only runs the tests for the data module:

ant dist-large dist-test-large
java -cp ~/tmp/emma-2.0.5312/lib/emma.jar emmarun \
  -cp develjar/junit.jar:dist/jar/cdk-svn-20061128.jar:dist/jar/cdk-test-svn-20061128.jar \
  -r html -sp src junit.textui.TestRunner org.openscience.cdk.test.MdataTest

Additional details

Description

Recently I discussed JUnit testing from within Eclipse , and blogged at several occasions about it in other situations. I cannot stress enough how useful unit testing is: it adds this extra set of eyeballs to make bugs shallow. And it does that, indeed. Ensuring that you actually test all the code you write, however, is not easy.

Identifiers

UUID
5d7dcd8b-64b0-47c3-8180-be7b4594175c
GUID
https://doi.org/10.59350/gtt31-tee03
URL
https://chem-bla-ics.linkedchemistry.info/2006/11/28/code-coverage-making-sure-your-code-is.html

Dates

Issued
2006-11-28T01:00:00
Updated
2025-02-16T01:00:00