Clover can measure code not only code coverage from whole application run but also a coverage generated by a single test case (JUnit / TestNG). It is possible to "hack" Clover and measure per-test coverage from manual test cases too. What has to be done is to "tell" Clover when manual test case starts and ends.
The easiest way to provide this information is to write a JUnit test case, with one test method for each manual test case. Clover will add "start test / end test" instrumentation to such methods. Next it's necessary run such JUnit test together with the application - thanks to the Clover's Distributed Coverage feature it's possible to run JUnit test and the application under test in separate JVMs.
1) Write JUnit test case having following features:
Example:
import junit.framework.TestCase; public class MyManualTest extends TestCase { public static void main(String args[]) { MyManualTest myTest = new MyManualTest(); myTest.waitUntilYourApplicationStarts(); int testNo = myTest.getTestNumber(); switch (testNo) { case 1: myTest.testManualTest1(); break; case 2: myTest.testManualTest2(); break; } } private int getTestNumber() { // e.g. entered by user / read from commandline arg ... return 1; } private void waitUntilYourApplicationStarts() { // e.g. "Press any key when ready" / check for existence of some marker file } private void waitUntilTestEnds() { // e.g. "Press any key when test is finished" / check for some marker file } public void testManualTest1() { // Clover will add "test start" here waitUntilTestEnds(); // Clover will add "test end" here } public void testManualTest2() { // Clover will add "test start" here waitUntilTestEnds(); // Clover will add "test end" here } }
2) Compile JUnit test case together with the application under test (produce two jars, for instance) with a Distributed Coverage feature enabled.
Example:
<clover-setup initstring="/path/to/my/clover.db" flushpolicy="interval" flushinterval="1000"> <distributedCoverage/> </clover-setup>
3) Run unit test and application:
a) unit test shall be launched with -Dclover.server=true parameter, e.g.
java -cp ...;clover.jar -Dclover.server=true MyManualTest
b) application shall be launched as usual (note that distributed coverage configuration is already compiled into instrumented classes), e.g.
java -cp ...;clover.jar MyApplication
4) Generate coverage report. In the HTML report it's possible to browse coverage contributed by given test case(s) by clicking "Show tests" link on the class summary page.
Because of fact that all manual test cases were wrapped into JUnit tests it's possible use per-test optimization:
It is also possible to browse "source file - test case" and "class file - test case" mapping using the SnapshotPrinter tool:
java -cp clover.jar com.atlassian.clover.optimization.SnapshotPrinter clover.snapshot.file
SnapshotPrinter can print mapping in plain text or in JSON format (since 3.1.11).