繁体   English   中英

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

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

有一个配置值rerunFailingTestsCount但我想运行一个可配置的测试方法,即使它成功了。 有什么选择吗?

我认为无法配置maven-surefire-plugin重新运行通过测试。

但是,您可以使用TestNG(而非JUnit) @Test批注配置单个测试的调用计数:

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

这将导致testSomething方法被测试5次。

如果您不想走TestNG路线,可以参考此答案以获取有关JUnit的解决方案。

如果您想通过实现IInvokedMethodListener beforeInvocation方法来对其进行配置,那么效果如下:

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

可以用System.getProperty替换它,但是要配置它。 您也可以通过传递测试名称来控制哪些测试来设置要更改的调用计数。

是的

<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