问题
I am using the Maven Surefire plugin in order to run just a specific suite of tests. For instance:
package suite;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import suite.slow.EvenSlowerClassTest;
import suite.slow.SlowClassTest;
@RunWith(Suite.class)
@Suite.SuiteClasses({
SlowClassTest.class,
EvenSlowerClassTest.class
})
public class SlowSuite {
}
By using the maven command
test -DrunSuite=**/FastSuite.class -DfailIfNoTests=false
I can run the FastSuite or SlowSuite test suites explicitly, however, how can I run all test suites that I have or all tests that are not covered in a test suite?
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<includes>
<include>${runSuite}</include>
</includes>
</configuration>
</plugin>
回答1:
What i have done in some of our projects, is to use <profiles>
in the pom.xml
to activate special suites of tests. If no profiles are active, all tests will be run with mvn test
(i hope that's what you are looking for)
Like so:
<profile>
<id>commit-test</id>
<build>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12.3</version>
<configuration>
<groups>com.test.CommitTest</groups>
</configuration>
</plugin>
</plugins>
</build>
Test classes in annotated like so:
@Category(CommitTest.class)
public class SomeTestClass {
}
I don't know if it works with @Suite
and @RunWith
but if your test suites aren't too many classes, it shouldn't be a difficult job to change that.
command: mvn clean test -Pcommit-test
回答2:
I think you can try with -DrunSuite=**/*Suite.class
来源:https://stackoverflow.com/questions/35009232/maven-surefire-junit-test-suite