Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Testing Stages in Maven

DZone's Guide to

Testing Stages in Maven

· DevOps Zone
Free Resource

Download “The DevOps Journey - From Waterfall to Continuous Delivery” to learn about the importance of integrating automated testing into the DevOps workflow, brought to you in partnership with Sauce Labs.

Test Stages in Development

There are a few stages in development testing. An SDLC figure it illustrates the different test stages in each development phase.


Test Stages in the Development Phase

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

In Maven, we have different lifecycles. By default, using Maven will help us to achieve test automation, but Maven phases help us to achieve the various stages, too.

Please have a look at the figure below, or read about it in detail here.


Step 1: Configuring the POM file

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

<!-- 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: The Java Class

This step is pretty simple, any Java class that follows this naming convention can be considered an integration test:

By default, failsafe will include all Java files with the name: **/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 failing.

Discover how to optimize your DevOps workflows with our cloud-based automated testing infrastructure, brought to you in partnership with Sauce Labs

Topics:

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}