2

我遇到了一个场景,我必须初始化一个测试用例

@Test
public void foo() {
}

以便 Maven 识别我的 TestFactory

@TestFactory
public Stream<DynamicTest> dynamicTestsFromStream() throws IOException{ 
...
}

经过一番研究,我遇到了这个:

与@Test 方法相比,@TestFactory 方法本身不是测试用例,而是测试用例的工厂。因此,动态测试是工厂的产品。 http://junit.org/junit5/docs/current/user-guide/#writing-tests-dynamic-tests

有没有办法在我的 Test 类中强制 TestFactory 在没有任何 @Test 方法的情况下运行,因为这样它是“伪造”我的 Jenkins 构建过程,因为我总是有 +1 测试运行和 +1 成功测试。

编辑:

mvn test从 cmd 控制台在 maven 项目中运行时会出现此问题。

我的依赖是:

                <dependency>
                    <groupId>org.junit.platform</groupId>
                    <artifactId>junit-platform-surefireprovider</artifactId>
                    <version>1.0.0-M1</version>
                    <scope>test</scope>
                </dependency>
                <dependency>
                    <groupId>org.junit.vintage</groupId>
                    <artifactId>junit-vintage-engine</artifactId>
                    <version>4.12.0-M1</version>
                    <scope>test</scope>
                </dependency>
                <dependency>
                    <groupId>org.junit.jupiter</groupId>
                    <artifactId>junit-jupiter-engine</artifactId>
                    <version>5.0.0-M1</version>
                    <scope>test</scope>
                </dependency>

概括

将我的 Maven JUnit 引擎升级到 M3 解决了这个问题。

4

0 回答 0