clover with gnu make

Shankar KC March 1, 2015

We are using old build system GNU make to build java projects. Can I use clover to get  test code coverage for our integration tests and optimize the integration tests? is there a sample project that I can refer?

1 answer

0 votes
Marek Parfianowicz
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
March 1, 2015

Hi Shankar, thanks a lot for great questions.

 

1) We are using old build system GNU make to build java projects. Can I use Clover [...] ?

Yes, it's possible. You can instrument Java sources using the CloverInstr command line tool:

https://confluence.atlassian.com/display/CLOVER/CloverInstr

and next use these instrumented sources as an input for javac.

 

2) Can I use Clover per test code coverage to get our integration per test coverage?

I assume that by integration tests you mean tests of an application running on a server - in other words, there are at least two JVMs running - one with unit tests and one with an application. Am I correct? If yes, then you have to enable Distributed Coverage feature. Example:

CloverInstr -dc ON

Please keep in mind that an application instrumented by Clover and running on a server must be able to locate the Clover database. Thus, in case your app server runs in a different working directory (than a build workspace) you have to either provide -Dclover.initstring=/path/to/clover.db JVM parameter or use an absolute path to a database during instrumentation:

CloverInstr -i /absolute/path/to/clover.db

You can find more hints here: https://confluence.atlassian.com/display/CLOVER/Using+Clover+for+web+applications

 

3) Can I [...] optimize the integration tests?

It depends how do you select and run your integration tests. For instance, do you call Ant's <junit> task for this? Or maybe you run some 'find' command to locate integration tests and next pass them to JUnit test runner manually?

The easiest way would be to try using the existing integrations in Clover (Ant, Maven ...) to optimize these tests.

However, if you cannot use this, you could try running Clover's com.atlassian.clover.api.optimization.TestOptimizer manually, but this would require some hacks. Code could look moreless like this:

// prepare list of test classes to be optimized
List&lt;Optimizable&gt; classes = Lists.newArrayList();
classes.add(new StringOptimizable("com.foo.Class1Test"));
classes.add(new StringOptimizable("com.foo.Class2Test"));
...

// run test optimizer
TestOptimizer optimizer = new TestOptimizer("path/to/clover.db", "path/to/clover.snapshot");
List&lt;Optimizable&gt; optimizedClasses =  optimizer.optimize(classes)

// run tests using the optimizedClasses list 

// update the optimization snapshot
CloverDatabase db = CloverDatabase.loadWithCoverage("path/to/clover.db", new CoverageDataSpec());
Snapshot snapshot = Snapshot.generateFor(db);
snapshot.store()

 

4) Is there a sample project that I can refer?

Unfortunately, I do not have any example for GNUmake.

 

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events