Maven Surefire Junit test suite

心已入冬 提交于 2019-12-23 17:27:00

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!