简体   繁体   中英

Is possible to run same test multiple times with Maven Surefire Plugin?

There is a config value rerunFailingTestsCount but I want to run a test method a configurable number of times even it is successful. Are there any options?

I don't think it is possible to configure maven-surefire-plugin to rerun passing tests.

However, you can configure the invocation count of a single test using the TestNG (not JUnit) @Test annotation:

@Test(invocationCount = 5)
public void testSomething() {
}

This will result in the testSomething method being tested 5 times.

If you don't want to go the TestNG route, you can refer to this answer for a solution with JUnit.

If you want to have it configurable by implementing the IInvokedMethodListener beforeInvocation method, something to the effect :

method.getTestMethod().setInvocationCount(Integer.parseInt(System.getProperty("configurablecount")));

System.getProperty can be replaced by however you want to configure it. You can also probably control which tests to set the invocation count to change by passing testnames.

Yes

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <configuration>
                <skip>true</skip>
            </configuration>
            <executions>
                <execution>
                    <id>phase-1</id>
                    <phase>test</phase>
                    <configuration>
                        <skip>false</skip>
                        <!-- Phase 1 configuration -->
                    </configuration>
                    <goals>
                        <goal>test</goal>
                    </goals>
                </execution>
                <execution>
                    <id>phase-2</id>
                    <phase>test</phase>
                    <configuration>
                        <skip>false</skip>
                        <!-- Phase 2 configuration -->
                    </configuration>
                    <goals>
                        <goal>test</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM