Testing Stages in Maven

Test Stages in Development

There are few stages in development testing. In an SDLC figure, it illustrates the different test stages in development phase.

Test Stages in Development Phase

  1. Unit Testing
  2. Integration Testing
  3. Test Automation 

In maven, we have different lifecycle. By default, using maven will help us to achieve test automation, however maven phases helps us to achieve the various stages too.

Please have a look at below figure or read the detail in here:

Step 1 Configuring POM file

However we can consume a maven plugin to be able to have integration test in our code. Have a look at the following example inside your build tags:

maven-failsafe-plugin
<!-- by default failsafe will include all java file with naming: **/IT*.java, **/*IT.java, **/*ITCase.java -->
<build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-failsafe-plugin</artifactId>
        <version>2.16</version>
        <executions>
          <execution>
            <goals>
              <goal>integration-test</goal>
              <goal>verify</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>

 

Step 2 Java Class

It is pretty simple, any java class that follows this naming convention then can be considered as Integration Test:

by default failsafe will include all java file with naming: **/IT*.java, **/*IT.java, **/*ITCase.java

Step 3 How to Execute the Integration Tests

Then you can have another job in your CI to execute integration test separately(mvn verify) to avoid your unit test fail.