Can clover get code coverage for those classes that get generated dynamically?

Hi,

In our application some JAVA classes are getting generated dynamically. May be this could be a sample http://www.rgagnon.com/javadetails/java-0039.html. In this sample you can see a dynamic method getting executed. Can I get code coverage details for such dynamic method? If yes can you please elaborate ?

Thanks

Shankar KC

1 answer

This widget could not be displayed.

Hi Shankar,

Yes, Clover can measure code coverage for such a dynamically generated class. What you have to do is:

 

1) Generate source code and store it in a file

In an article linked by you it's being done in lines:

File sourceFile   = new File("/temp/Hello.java");
FileWriter writer = new FileWriter(sourceFile);
...
writer.close();

 

2) Call CloverInstr tool in order to add Clover code to it

You can either call it from a command line, for instance:

java -cp /path/to/clover.jar com.atlassian.clover.CloverInstr -i path/to/clover.db -d /temp/clover-instr /temp/Hello.java

 

or directly from code:

import com.atlassian.clover.CloverInstr;

String[] cliArgs =  { 
    "-i", "path/to/clover.db", 
    "-d", "/temp/clover-instr", 
    "/temp/Hello.java" };

int result = CloverInstr.mainImpl(cliArgs);
if (result != 0)    {
    // problem during instrumentation
}

 

3) Call java compiler on an instrumented file

In our example you'd have to run a JavaCompiler task on the /temp/clover-instr/Hello.java.

 

Cheers
Marek

Suggest an answer

Log in or Sign up to answer
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Posted Wednesday in New to Jira

Are you planning to trial, or are currently trialling Jira Software? - We want to talk to you!

Hello! I'm Rayen, a product manager at Atlassian. My team and I are working hard to improve the trial experience for Jira Software Cloud. We are interested in   talking to 20 people planning t...

121 views 2 0
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you