5

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>
A_Di-Matteo
  • 26,902
  • 7
  • 94
  • 128
luca.p.alexandru
  • 1,660
  • 5
  • 23
  • 42

2 Answers2

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

Martin Hansen
  • 2,033
  • 1
  • 18
  • 34
1

I think you can try with -DrunSuite=**/*Suite.class

hao jiang
  • 81
  • 1
  • 1
  • 1
    There does not exist a property like `runSuite` in [maven-surefire-plugin](https://maven.apache.org/surefire/maven-surefire-plugin/test-mojo.html). – khmarbaise Jan 26 '16 at 11:47
  • No property `runSuite` out-of-the-box, but it can be defined with https://stackoverflow.com/questions/11762801/run-junit-suite-using-maven-command (accepted answer) – Florian H. Apr 04 '22 at 15:22