Kevin
Kevin

Reputation: 6312

Maven: How can I setup maven to run unit test and integration test separately

I have a question regarding maven.

I have got Unit Tests which have file name ending with *Test and integration test whose file name ends with *IT.

My understanding is that surefire will run the unit test and failsafe will run the integration test.

When I run: mvn clean install

Both unit test and integration tests are run.

When I run:

mvn verify

Both of these tests are run too.

Is there anyway I can configure maven so that when I use: mvn clean install, only the unit tests are run. And when I use mvn verify, only integration tests are run?

My build section of POM is as follows:

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.3.2</version>
            <configuration>
                <source>1.6</source>
                <target>1.6</target>
            </configuration>
        </plugin>

        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>failsafe-maven-plugin</artifactId>
            <version>2.4.3-alpha-1</version>
            <executions>
                <execution>
                    <goals>
                        <goal>integration-test</goal>
                        <goal>verify</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>

    <resources>
        <resource>
            <directory>src/main/resources</directory>
        </resource>
    </resources>
</build>

Many thanks

Upvotes: 3

Views: 2515

Answers (2)

StefanHeimberg
StefanHeimberg

Reputation: 1465

Unit- Integration- and Systemtest Setup with Maven

I have created a GitHub repository where you can see a possible Setup with maven. i post this here because i want to share my idee about this setup with others and i think this could be found when someone search about testing with maven on SO

The Repository contains a fully functional setup.

GitHub Repository: https://github.com/StefanHeimberg/maven3-unit_integration_systemtest-setup

Features

  • Maven 3.3
  • Flyway for DB Migration of the Production and Systemtest Database
  • Arquillian for Integration Test execution
  • Mockito for Unit Testing

Unit-Tests

  • Only one Class / Business function ist tested
  • No Database
  • No Container
  • Smallest possible unit to test
  • Dependencies to other Classes are Mocked. (Mockito)
  • Tests are inside src/test of the artifact where the unit under test class reside

Integration-Tests

  • Multiple Classes / Business functions are orchestrated and tested together
  • In-Memory Database per TestCase
  • EE Container. Started once for all Integration Tests
  • Arquillian Remote Managed Wildfly
  • Datasource Deployment per TestCase inside arquillian war (*-ds.xml)
  • DB Tables are generated from JPA DDL (hibernate.hbm2ddl.auto=create-drop)
  • Arquillian Deployments contains only the classes neede for the testcase itself
  • Testdata loaded manually inside @Test or @Before method... (test data builders...)
  • Tests are separated from other code

System-Tests

  • Full Wildfly deployment of the final WAR/EAR File.
  • Container configuration via *.cli command line commands
  • Read Database used because we need (hibernate.hbm2ddl.auto=validate)
  • Database setup before deployment with maven-flyway-plugin
  • Testdata loaded with sql-maven-plugin
  • Tests are separated from other code

Upvotes: 0

nobeh
nobeh

Reputation: 10049

As mentioned here, by convention, let's say integration tests are named as in TestNameIT.java and unit tests as in TestNameUT.java, you can use includes to filter integration tests or unit tests.

Upvotes: 1

Related Questions