Steps that bring to this warning
1. Create simple maven project
2. In pom.xml add maven-clover2-plugin and reporting plugin
3. from command line
After the last step the following warning is displayed - WARN: No coverage recordings found. No report will be generated.
The things are different when instead of running from command line, running from Eclipse by:
After these three steps report is generated.
My point is to make it work when running from cmd.
Will appraciate anykind of help/suggestion
Thanks,
Sevak
Did you run your tests (mvn test)?
this is the next what I would like to ask you, look we have two maven projects - DEV project and separately QA project, which is testing DEV codes (all the tests are located in QA project ), we do it using testNG.
So how can we compute code coverage in this particular case?
Shell we also instrument QA project codes? Or there should be different approach?
Please advise.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
In order to get a code coverage report you have to call:
1) mvn clean - in order to ensure that old, non-instrumented classes will be removed (unless you have a dedicated build where code is always compiled with Clover enabled)
2) mvn clover2:setup compile or mvn clover2:setup test-compile - in order to enable Clover and to compile application and test classes
3) mvn test or mvn integration-test or mvn verify - in order to run your tests and record code coverage
4) mvn clover2:aggregate or mvn clover2:merge - in order to merge Clover databases (unless you use singleCloverDatabase=true option)
4) mvn clover2:clover - to generate Clover reports
All these goals can be run in a single mvn command. So typically it is:
mvn clean clover2:setup verify clover2:aggregate clover2:clover
You wrote that you call the "mvn clean install" (followed by mvn with Clover goals). May I ask you why do you call the "install" goal? It it because you need to install some artifacts for further testing?
You wrote that you have tests in a separate QA project. How does the QA project load code from a DEV project? I suppose that you have a following setup:
* first you run "mvn install" in DEV project to install DEV artifacts (JARs) into local ~/.m2 cache
* QA project has dependencies to DEV artifacts (JARs) in it's pom.xml, so
* next you run "mvn test" on QA and it fetches JARs from ~/.m2 and runs tests on them.
Is my guess correct?
Do you build DEV and QA projects on the same machine? Is it a dedicated machine for QA testing? Why am I asking? Well, because we may need to figure out how to pass DEV artifacts to QA, ensuring that:
* your QA will fetch instrumented DEV jars and not the normal ones and
* you will not accidentally install/deploy instrumented DEV jars in a location (directory/server/repostory...) where you expect to have non-instrumented jars only
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
before describing in more details my situation, I would like to make clear for me something. So my general understanding is that, if I have instrumented jar of project "A", then I can calculate coverage even by simply running some method of other project named "B", which just calls one of the methods of instrumented "A" project, (I mean there is no need to have junit tests or tests written using testng in project "B", in order to calculate coverage of "A")
Now let me describe in more details what I have done.
1. Created Dev maven project
2. run
3. As a result of step "2", I have instrumented jar in target folder also in local repo, also coverage.db file is created under .clover folder
4. Created QA maven project and include Dev project as a maven dependancy
5. Wrote method TestClass#test() in QA project which calls some method of Dev project
6. run method TestClass#test().
As a result of step "6" I expect that coverage.db should be filled somehow(method usage of Dev project will be recorded) and when I run mvn clover2:clover I would get the final report.
But instead of that, I am getting the follwoing exception
Exception in thread "main" java.lang.NoClassDefFoundError: Could not initialize class com.sevak.DevCode$__CLR3_3_000hwc3qt0q
at com.sevak.DevCode.someFunc(DevCode.java:7)
at com.sevak.TestClass.test(TestClass.java:7)
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.
if I have instrumented jar of project "A", then I can calculate coverage even by simply running some method of other project named "B"
Indeed. As soon as code in project A is instrumented, it will record code coverage, no matter whether the project B has been instrumented or not.
3. As a result of step "2", I have instrumented jar in target folder also in local repo, also coverage.db file is created under .clover folder
4. Created QA maven project and include Dev project as a maven dependancy
Because of the fact that you're using clover2:instrument goal, Clover forks a parallel build life cycle and all artifacts produced have the -clover.jar suffix. Can you confirm that you QA project has a dependency to DEV project with a <classifier>clover</classifier>?
But instead of that, I am getting the follwoing exception:
Exception in thread "main" java.lang.NoClassDefFoundError: Could not initialize class com.sevak.DevCode$__CLR3_3_000hwc3qt0q
The "NoClassDefFoundError ...SomeClass$__CLR..." means that JVM was unable to load a class instrumented by Clover. It means that you don't have a clover.jar on your class path in the QA project.
Please add a following dependency to your QA project:
<dependency> <groupId>com.cenqua.clover</groupId> <artifactId>clover</artifactId> <version>3.3.0</version> </dependency>
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you very much Marek for your support, you help me much really.
The exception is fixed now.
As I describe in my last comment step #6 - run method TestClass#test() from QA project
Here I expect that the method call should be recorded in .clover/coverage.db,
but in fact it does not, since in step #7- when I run HtmlReportRunner.java, report is being generated, but there is no record as a result of TestClass#test(){DevCode.someFunc(); } call. The report only contains unit tests coverage, which I have in Dev project.
What should I do here to make coverage.db contain also method calls from QE project?
I guess that instrumented codes get path of coverage.db from instrumentation.ser file located in jar.
below is the clover related config part of Dev project pom.xml. Am I missing any configuration?
<build> <plugins> <plugin> <groupId>com.atlassian.maven.plugins</groupId> <artifactId>maven-clover2-plugin</artifactId> <version>3.3.0</version> <configuration> <licenseLocation>C:\clover.license</licenseLocation> <cloverDatabase>C:\Users\sts\Workspaces\MyEclipse Professional 2014\myClover2\.clover\coverage.db</cloverDatabase> <cloverMergeDatabase>C:\Users\sts\Workspaces\MyEclipse Professional 2014\myClover2\.clover\coverage.db</cloverMergeDatabase> <includesTestSourceRoots>true</includesTestSourceRoots> <singleCloverDatabase>true</singleCloverDatabase> </configuration> </plugin> </plugins> </build> <reporting> <plugins> <plugin> <groupId>com.atlassian.maven.plugins</groupId> <artifactId>maven-clover2-plugin</artifactId> </plugin> </plugins> </reporting>
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.