0

I'm trying to set up the followings :

1 During the test phase of maven i only want fast test to execute
2 I want integration (slow test) to execute during verify phase

Here is my config '''

</dependencies>
    <dependency>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>3.0.0-M5</version>
    </dependency>
    <dependency>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-failsafe-plugin</artifactId>
        <version>3.0.0-M5</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.junit.jupiter</groupId>
        <artifactId>junit-jupiter-api</artifactId>
        <version>${junit-platform.version}</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.junit.jupiter</groupId>
        <artifactId>junit-jupiter-engine</artifactId>
        <version>${junit-platform.version}</version>
        <scope>test</scope>
    </dependency>

</dependencies>

<build>
    <plugins>
        <plugin>
            <artifactId>maven-failsafe-plugin</artifactId>
            <version>3.0.0-M5</version>
            <executions>
                <execution>
                    <phase>integration-test</phase>
                    <goals>
                        <goal>integration-test</goal>
                        <goal>verify</goal>
                    </goals>
                    <configuration>
                        <groups>fast,slow</groups>
                    </configuration>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>3.0.0-M5</version>
            <configuration>
                <groups>fast</groups>
                <excludedGroups>slow</excludedGroups>
            </configuration>

        </plugin>

'''
When i execute mvn test, only fast tests get executed, good. But when i execute mvn verify (for sonar) i also only get fast, but i want fast and slow. I think i misunderstanding how failsafe works with surefire.

Thanks for your help


For people like me. You often see Failsafe plugin used to separate fast and slow test. In fact, failsafe is used to configure CI tests from Unit tests. If you only want to separate fast and slow test, juste configure categories and profiles :

<profiles>
    <profile>
        <id>SlowTests</id>
        <properties>
            <groups>slow</groups>
        </properties>
    </profile>
    <profile>
        <id>FastTests</id>
        <properties>
            <groups>com.decathlon.kpi.category.FastTest</groups>
        </properties>
    </profile>
</profiles>
  

And the test category :

@Target({ ElementType.TYPE, ElementType.METHOD })
@Retention(RetentionPolicy.RUNTIME)
@Tag("fast")
public @interface FastTest {
}
Coshi
  • 11
  • 3
  • Do your integration tests end with IT? Check these to see if they can help you https://www.baeldung.com/maven-integration-test and https://stackoverflow.com/questions/11542530/using-junit-categories-with-maven-failsafe-plugin – pringi Feb 17 '22 at 12:12
  • I start to understand my mistake. I want to use failsafe for the wrong reasons. My goal is to execute fast and slow test at different moment of maven lifecycle, not on different environments. So i thought that failsafe would help me deal with this. But i think that surefire alone is enough. – Coshi Feb 17 '22 at 12:56
  • Probably you want to use Categories. See this: https://stackoverflow.com/questions/3100924/how-to-run-junit-tests-by-category-in-maven – pringi Feb 17 '22 at 12:58

0 Answers0