Knowledge Base > JCover CLI > Running JCover tests
Running JCover tests
- 1. Running tests using the “DiffblueTest” suffix (this is recommended)
- 2. Running tests using different test roots (no test suffix required)
Tests can be run either with or without a suffix, as explained below:
1. Running tests using the “DiffblueTest” suffix (this is recommended)
Generating tests using a command such as:
$ jcover --maven --test-verification --class-suffix DiffblueTest
will add the tests to the same test root as your existing tests, but these tests can be differentiated by the DiffblueTest suffix added to the end of the tests.
You can also:
Run only Diffblue tests:
$ mvn clean test -Dtest=*DiffblueTest.java
Run only existing tests:
$ mvn clean test -Dtest=\!*DiffblueTest.java
Run both sets of tests together:
$ mvn clean test
The JCover tests can also be created in a separate directory to the existing tests, such as src/jcover/java
, but this will need to be added as an additional test source. To do this, use the build-helper-maven-plugin
as shown below:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.4</version>
<executions>
<execution>
<id>add-test-source</id>
<phase>generate-test-sources</phase>
<goals>
<goal>add-test-source</goal>
</goals>
<configuration>
<sources>
<source>src/jcover/java</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
2. Running tests using different test roots (no test suffix required)
Generating tests using a command such as:
$ jcover --maven -d src/jcover/java --test-verification
will save tests to the src/jcover/java
directory. To do this, add the following to the file pom.xml:
<profiles>
<profile>
<id>DiffblueTests</id>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.4</version>
<executions>
<execution>
<id>add-test-source</id>
<phase>generate-test-sources</phase>
<goals>
<goal>add-test-source</goal>
</goals>
<configuration>
<sources>
<source>src/jcover/java</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.4</version>
<executions>
<execution>
<id>add-test-source</id>
<phase>generate-test-sources</phase>
<goals>
<goal>add-test-source</goal>
</goals>
<configuration>
<sources>
<source>src/test/java</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
<testSourceDirectory>somePlaceThatDoesn'tExist</testSourceDirectory>
</build>
Once this is in place you can run mvn clean test
as usual and the original tests will be run, but if you run mvn clean test -P DiffblueTests
, then only the Diffblue tests will be run.