11

I have written a JUnit test suite for running multiple test cases.

Now I want to run my test suite class (AllTest.java) at once so that all tests are triggered, carried and managed by one class. I know maven-failsafe-plugin is available, but is there any other easier way to invoke a JUnit test suite from Maven?

I dont want to use another plugin for this.

This is my current maven-failsafe-plugin configuration:

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-failsafe-plugin</artifactId>
  <version>2.9</version>
  <configuration>
    <includes>
      <include>**/AllTests.java</include>
    </includes>
  </configuration>
  <executions>
    <execution>
      <id>integration-test</id>
      <goals>
        <goal>integration-test</goal>
      </goals>
    </execution>
    <execution>
      <id>verify</id>
      <goals>
        <goal>verify</goal>
      </goals>
    </execution>
  </executions>
</plugin>
Matthew Farwell
  • 60,889
  • 18
  • 128
  • 171
Chetan
  • 1,507
  • 7
  • 30
  • 43
  • You could use default `surefire` plugin with the same configuration. – Andrew Logvinov Dec 17 '12 at 10:42
  • I dont want to use maven-failsafe-plugin, And i have tried with surefire plugin. But it is not picking up class which annotated as @RunWith(Suite.class) and @SuiteClasses({ TestClassMyPOJOBase.class }) – Chetan Dec 17 '12 at 11:07
  • Are you having unit tests or integration tests? Unit Test => maven-surefire-plugin, integration tests => maven-failsafe-plugin. You shouldn't work with suites, cause Maven-surefire or maven-failsafe will take care of running all tests. Furthermore don't forget the naming conventions for Unit tests and for integration tests. – khmarbaise Dec 18 '12 at 12:39

2 Answers2

14

You can run it with -Dit.test=[package].AllTest (-Dtest with surefire), or configure the included tests in the pom:

  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.22.1</version>
    <configuration>
      <includes>
        <include>AllTest.java</include>
      </includes>
    </configuration>
  </plugin>
artbristol
  • 32,010
  • 5
  • 70
  • 103
  • 2
    second option worked for me.. but -Dtest and Dit.test=[package].AllTest didnt really work for me.. Am I missing something?? – Chetan Dec 17 '12 at 18:11
  • I don't think fully qualified package names were supported until v2.19.1. The snippet above references v2.12.4. – user6629913 Jan 08 '19 at 18:59
2

You can run test suite using following maven command:

 mvn test -Dtest=x.y.z.MyTestSuite

Note : x.y.z is the package name.

swapyonubuntu
  • 1,952
  • 3
  • 25
  • 34