How to programatticaly read pertestcoverage information from clover.db

Aryan April 21, 2015

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

I went through https://confluence.atlassian.com/display/CLOVER/Database+Structure but sample code as well as javadocs (https://docs.atlassian.com/atlassian-clover/latest/)  does not contain details for com.atlassian.clover.recorder.PerTestCoverage and  com.atlassian.clover.CloverDatabase 

 

Thanks!

 

2 answers

0 votes
Aryan April 21, 2015

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("com.abc.myclass");
Collection<TestCaseInfo> tcinfo = classInfo.getTestCases();

 

returns tcinfo of size 0

Marek Parfianowicz
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
April 21, 2015

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

Aryan April 21, 2015

Yes I do have those files in same folder where clover.db is. DB is generated using help provided on thread https://answers.atlassian.com/questions/13408794/clover-per-test-coverage-for-automated-functional-test So i have Clover-Merged.db = Clover-app.db + Clover-test.db And i am passing Clover-Merged.db to above code.

Aryan April 21, 2015

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

Marek Parfianowicz
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
April 21, 2015

good point!

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

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>.

Update:

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>.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events