问题
I am using Cobertura in eclipse to generate the code coverage for my java maven project and it works fine. I have around 15 tests classes. Whenever I am running maven build, it generates code coverage for all those 15 classes.
Is there any way, I can run cobertura code coverage report for few of my test classess instead of all the test classes? I also have AllTests
in which I have mentioned only few of my test classes but I guess cobertura doesn't use AllTests
.
回答1:
If you are using the Maven Cobertura plugin, you can specify filtering using two separate tags:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<version>${cobertura.version}</version>
<configuration>
<instrumentation>
<ignores>
<ignore>org.apache.log4j.*</ignore>
...
</ignores>
<excludes>
<exclude>**/package1/package2/**/*.class</exclude>
...
</excludes>
</instrumentation>
</configuration>
</plugin>
<ignores>
tells Cobertura to exclude all calls to the specified package/class. The example above will ignore all lines that are log4j logging calls.
<excludes>
tells Cobertura to not instrument certain files. Hits to those classes are not recorded during the test run. Here **
indicates recursive search (any directory at any depth below current). So the example states: Exclude any classes that have the package1.package2
package anywhere in their fully qualified name.
You also have an <includes>
to specify a white-list of classes instead of <excludes>
.
Other details can found here: Mojo's Maven plugin for Cobertura - Usage
来源:https://stackoverflow.com/questions/24110634/how-to-run-cobertura-code-coverage-for-few-test-classes-not-all-of-my-test-class