4

I have an interface like this:

public interface IntegrationTest {
}

I configure the failsafe plugin like this:

 <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-failsafe-plugin</artifactId>
    <version>2.14</version>
    <configuration>
        <groups>acme.test.IntegrationTest</groups>
    </configuration>
    <executions>
        <execution>
            <goals>
                <goal>integration-test</goal>
            </goals>
        </execution>
    </executions>
</plugin>

If I then create an integration test like this

@Category(IntegrationTest.class)
public class ExampleClassIntegrationTest {

@Test
public void slow_and_painful_test() {

This test will not run.

If I however name the class according to the Inclusions and Exclusions of Tests

**/IT*.java
**/*IT.java
**/*ITCase.java

Like so:

@Category(IntegrationTest.class)
public class ExampleClassIT {

@Test
public void slow_and_painful_test() {

The test runs fine. Why do I have to name the test AND have an annotation when i use the groups-tag? Am I missing something? The documentation on using JUnit states that you can use the Category annotation at the class level.

Jörgen Lundberg
  • 1,799
  • 3
  • 22
  • 31
  • To distinguish unit and integration test are simply based on the naming convention so no need to use a group in JUnit (Apart from being not the best choice for integration tests). – khmarbaise May 28 '13 at 12:12
  • @khmarbaise I disagree, Categories are an excellent way to organize using tests without being locked into a naming convention. This is why JUnit added them and why the various Maven plugins support them. – John B May 28 '13 at 12:20
  • Have you tried excluding the Category? Do you need BOTH or is the Category being ignored completely? – John B May 28 '13 at 12:22
  • What version of JUnit have you included in your project? – John B May 28 '13 at 12:24
  • This is similar to this question but the plugin version is different: http://stackoverflow.com/questions/16768732/why-does-excludegroups-work-but-groups-doesnt – John B May 28 '13 at 12:24

2 Answers2

9

Thats because these are the default java classes which fail safe plugin includes when executed. You can however over ride this in your pom with tag : E.g

<includes>
<include>**/*.java</include>
</includes>

To include all the java files.

0

You should either add JUnit as a dependency (>4.8) which is already done or in particular add the following to your failsafe-plugin configuration:

<plugins>
[...]
  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-failsafe-plugin</artifactId>
    <version>2.14.1</version>
    <dependencies>
      <dependency>
        <groupId>org.apache.maven.surefire</groupId>
        <artifactId>surefire-junit47</artifactId>
        <version>2.14.1</version>
      </dependency>
    </dependencies>
  </plugin>
[...]
</plugins>

But i assume it will not change the situation.

khmarbaise
  • 92,914
  • 28
  • 189
  • 235
  • I already had JUnit 4.10 as a dependency. And you are correct, changing the version and adding the surefire-junit47 dependency did not solve the problem. – Jörgen Lundberg May 28 '13 at 14:57