Enabling Code Coverage in Rational Application Developer

RAD 8 Source Code Coverage Configuration
Code coverage is the method of analyzing your source code to see what lines of code are covered by unit tests. In the case of Java, JUnit is the unit test toolset of choice. Code coverage tools came available in RAD 8, and have been improved in 8.5. Its very simple to enable this on a project. In fact you should enable it on all your projects to help instrument what you've tested.

RAD8 Code Coverage IDE instrumentation

Team Concert Code Coverage Report
To enable the code coverage, go to your project properties, then narrow down to Code Coverage as showing in the image. You can specify the type of coverage you want. For example, you may want to be sure you cover 80% of your methods, but not care about testing declarations, or constants. You might want to only make sure you've tested it by block level. All of which can be controlled at a package, source, type, and method level of coverage. Once you have enabled it, you can then run a unit test on your entire source folder. This will then give you  instrumentation directly in the source code. Packages that have passed the code coverage requirements will have the text of the package in green. Those that have not passed will have it in red.

You can also analyze code coverage when you do a build in Rational Team Concert. This will then put the code coverage report on the build result as shown in this image.

Now, you are probably thinking, "why is this important"? Simply put, if you have not sufficiently tested the appropriate amount of code, how much faith can you put in a suite of unit tests that consistently passes? You really cant. This is why code coverage is important. The greater the amount of code coverage, and the more successful the unit tests, the better quality is the code. That is not to say that it will cover all defects! No, for that you still must do performance and functional (integration) testing.

Labels: , ,