Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running JUnit test suite using Maven

Tags:

junit

maven

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>
like image 742
Chetan Avatar asked Dec 17 '12 09:12

Chetan


2 Answers

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>
like image 127
artbristol Avatar answered Nov 15 '22 23:11

artbristol


You can run test suite using following maven command:

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

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

like image 30
swapyonubuntu Avatar answered Nov 15 '22 23:11

swapyonubuntu