简体   繁体   English

是否可以使用 Maven Surefire 插件多次运行相同的测试?

[英]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.有一个配置值rerunFailingTestsCount但我想运行一个可配置的测试方法,即使它成功了。 Are there any options?有什么选择吗?

I don't think it is possible to configure maven-surefire-plugin to rerun passing tests. 我认为无法配置maven-surefire-plugin重新运行通过测试。

However, you can configure the invocation count of a single test using the TestNG (not JUnit) @Test annotation: 但是,您可以使用TestNG(而非JUnit) @Test批注配置单个测试的调用计数:

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

This will result in the testSomething method being tested 5 times. 这将导致testSomething方法被测试5次。

If you don't want to go the TestNG route, you can refer to this answer for a solution with JUnit. 如果您不想走TestNG路线,可以参考此答案以获取有关JUnit的解决方案。

If you want to have it configurable by implementing the IInvokedMethodListener beforeInvocation method, something to the effect : 如果您想通过实现IInvokedMethodListener beforeInvocation方法来对其进行配置,那么效果如下:

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

System.getProperty can be replaced by however you want to configure it. 可以用System.getProperty替换它,但是要配置它。 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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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