How to programatticaly read pertestcoverage information from clover.db

Intention is to programtically figure out which all tests covers any piece of code, Method, Class or Package. 

I went through but sample code as well as javadocs (  does not contain details for com.atlassian.clover.recorder.PerTestCoverage and  com.atlassian.clover.CloverDatabase 




2 answers

0 votes

In case you want to find a list of tests associated with a given test class, you can cast com.atlassian.clover.api.registry.ClassInfo to com.atlassian.clover.registry.entities.FullClassInfo and call the getTestCases() method which returns Collection<com.atlassian.clover.registry.entities.TestCaseInfo>.


In case you want to find all tests hitting given element, you can cast BranchInfo / ElementInfo / MethodInfo etc to corresponding FullBranchInfo / FullElementInfo / FullMethodInfo etc ... and next pass it as a parameter to the CloverDatabase.getTestHits(CoverageDataRange range) method, which returns Set<TestCaseInfo>.

Not working for me, I tried below code


CloverDatabase db = CloverDatabase.loadWithCoverage(args[0], new CoverageDataSpec());
ProjectInfo projectInfo = db.getRegistry(). getProject();
FullClassInfo classInfo = (FullClassInfo)projectInfo.findClass("");
Collection<TestCaseInfo> tcinfo = classInfo.getTestCases();


returns tcinfo of size 0

Do you have per-test coverage files (clover*.s)?

Yes I do have those files in same folder where clover.db is. DB is generated using help provided on thread So i have Clover-Merged.db = Clover-app.db + Clover-test.db And i am passing Clover-Merged.db to above code.

db.getTestHits() worked, it returns the exact tests hitting any piece of Code.

good point!

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Thursday in Jira

Updates to give you visibility into what's coming in Jira Server and Data Center

Hello, Community! My name is Gosia and I'm a Product Manager on Jira Server and Data Center here at Atlassian. Since 2002 when we launched our public issue tracker, jira.atlass...

266 views 1 10
Read article

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