Hi All,
I was able to generate clover HTML report for 5 test cases run on an instrumented source. Now, the HTML report shows 80% covered for a source file. The report also gives a way for me to select the tests hitting this source file to show the coverage for a particular test method.
1. How can I get this functionality in the JSONReporter? In short, what am trying to do is to build a heuristic to consider a test case for execution if the test hits a source file with 80% coverage. As of today, the JSONReporter gets overall coverage as below:
"stats": {
"Complexity": 56,
"CoveredElements": 153,
"ErroneousTests": 0,
"FailingTests": 0,
"PassingTests": 0,
"PcErroneousTests": -1,
"PcFailingTests": -1,
"PcPassingTests": -1,
"TestExecutionTime": 0,
"Tests": 0,
"TotalPercentageCovered": 62.19512,
"UncoveredElements": 93
}
2. Why does "Tests", "PassingTests", "FailingTests" field show 0? I have checked multiple source files being hit by this test case and all of them show the fields as 0.
Note: Am using distributedCoverage with per-test mapping to get the report for end-to-end tests.
Hi! Unfortunately, as far as I remember, JSON reporter does not provide per-test coverage statistics, you can find it only in the HTML report.
In order to get the data you want, you can read data directly from the clover.db database. Please have a look at examples provided here:
http://openclover.org/doc/manual/latest/developer-guide--database-structure.html
chapter "Reading from a Clover database". Once you load the database with coverage, you can iterate over packages, source files, classes etc.
Entities like FileInfo extend the InstrumentationInfo interface which returns an index to retrieve coverage hit count.
The CoverageData class has methods like mapTestsAndCoverageForFile, getTestsCovering or getHitsFor which will let you run different queries. You can get this class from CloverDatabase#getCoverageData.
I tried to get the coverage data from CloverDatabase but coverage is in BitSet. Am not sure how to extract information from it. Are there any short examples of extracting this data that can give me some indication of how it can be done?
I also see that the data present in coverage database is not a direct percentage for a per test coverage. Is it possible to extract coverage percentage for a particular test case, given that this is an end-to-end test and the database is a merged one?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
BitSet is a map (covered/uncovered) to code elements (method entries, statements, branches). Index from InstrumentationInfo tells at which bit from a BitSet you have to look.
The com.atlassian.clover.CoverageData#mapTestsAndCoverageForFile returns a map of: test case, bitset with a bitmask applied for a given file.
The FileInfo#getDataIndex returns first index to look at in the bitset above.
The FileInfo#getDataLength returns size - so you look [index .. index + length).
If you count bits set to 1 in this range and compare with getDataLength you will get a pretty good value of per-test code coverage for this file.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
CloverDatabase db = CloverDatabase.loadWithCoverage("joda_time/target/clover/clover.db", new CoverageDataSpec());
ProjectInfo projectInfo = db.getRegistry().getProject();
// print some project details
printProject(projectInfo, System.out);
CoverageData cd= db.getCoverageData();
Map<TestCaseInfo, BitSet> map = cd.mapTestsAndCoverageForFile((FullFileInfo) fileInfo);
I want to get which lines are executed by each test case, but I dont know how to create FullFileInfo
Also can you help out how to get the line numbers of the executed statements for each testcase?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
CloverDatabase#getModel()
FullProjectInfo#getPackageRoots() or #findPackage()
PackageInfo#getFiles()
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
getFiles returns FileInfo and I can cast this to FullFileInfo. I was looking for alternatives I don't have to do casting.
Also, any idea on how to have all tests that cover a particular statement from a file? Is it even possible?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I wanted to create this question under Clover but for some reason, I cannot find that product under the dropdown anymore.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I have moved the question for you. :)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.