Recommended: Sing it, brah! 5 fabulous songs for developers
JW's Top 5
svn co https://designbycontract.googlecode.com/svn/trunk/examples/maven/categor...
mvn clean install
public interface IntegrationTest {}
import org.junit.experimental.categories.Category;Categories can be used to mark classes or methods. Really in my opinion you should only mark a class.
@Category(IntegrationTest.class)
public class ExampleIntegrationTest{
@Test
public void longRunningServiceTest() throws Exception {
}
}
<plugin>There are 2 very important parts. The first is to configure surefire to exclude all of the integrations tests.
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.11</version>
<dependencies>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-junit47</artifactId>
<version>2.12</version>
</dependency>
</dependencies>
<configuration>
<includes>
<include>**/*.class</include>
</includes>
<excludedGroups>com.test.annotation.type.IntegrationTest</excludedGroups>
</configuration>
</plugin>
<excludedGroups>com.test.annotation.type.IntegrationTest</excludedGroups>Surefire will run all of your tests, except those marked as an integration test.
<dependencies>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-junit47</artifactId>
<version>2.12</version>
</dependency>
</dependencies>
mvn clean testYou can see from the output below that the unit test is run, but not the integration test.
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running com.test.EmptyUnitTest
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0 sec
Results :
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
<plugin>The configuration uses a standard execution goal to run the failsafe plugin during the integration-test phase of the build.
<artifactid>maven-failsafe-plugin</artifactId>
<version>2.12</version>
<dependencies>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-junit47</artifactId>
<version>2.12</version>
</dependency>
</dependencies>
<configuration>
<groups>com.test.annotation.type.IntegrationTest</groups>
</configuration>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
</goals>
<configuration>
<includes>
<include>**/*.class</include>
</includes>
</configuration>
</execution>
</executions>
</plugin>
And again the JUnit provider must be correctly configured.com.test.annotation.type.IntegrationTest
<dependencies>That’s it!
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-junit47</artifactId>
<version>2.12</version>
</dependency>
</dependencies>
mvn clean installThis time as well as the unit test running, the integration tests are run during the integration-test phase.
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running com.test.AnotherEmptyIntegrationTest
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.016 sec
Running com.test.EmptyIntegrationTest
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0 sec
Results :
Tests run: 2, Failures: 0, Errors: 0, Skipped: 0
svn co https://designbycontract.googlecode.com/svn/trunk/examples/maven/code-co...Its based on this example
mvn clean install -Ptomcat-embedded