未运行/检测到JUnit 5测试

时间:2018-09-28 11:04:03

标签: java maven junit maven-surefire-plugin junit5

我正在使用JUnit 5.3.1,并使用maven运行测试。有一个参数测试未运行。我正在使用maven-surefire-plugin,这是从我的pom.xml中获取的

<build>
        <plugins>
            <plugin>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.19</version>
                <configuration>
                    <includes>
                        <include>**/*Tests.java,**/*Test.java</include>
                    </includes>
                </configuration>
            </plugin>
...
</build>

当我运行mvn test命令时,这是输出的一部分:

Running com.growthintel.elastic_plugin.cid_suppressions.CheckCompanyTest Tests run: 0, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0 sec - in com.growthintel.elastic_plugin.cid_suppressions.CheckCompanyTest

没有从CheckCompanyTest文件中检测到测试! Maven正在检测文件,但未检测到文件中的任何测试。我没有遵循参数化测试的命名约定吗?这是测试文件:

public class CheckCompanyTest {

        private static Stream<Arguments> getListOfSuppressedFilePaths() {
            ...
        }

        @ParameterizedTest(name = "run #{index} with args: {arguments}")
        @MethodSource("getListOfSuppressedFilePaths")
        public void test_HasSuppressedCid(List<String> cidSuppressionFilePaths) {
            ...
}

2 个答案:

答案 0 :(得分:2)

您可以使用junit-platform-surefire-engine(如@Niby建议),或将maven-surefire-plugin升级到2.22.0,并使用对JUnit Jupiter的内置支持:

<plugin>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.22.0</version> <!-- Here -->
    <configuration>
        <includes>
            <include>**/*Tests.java,**/*Test.java</include>
        </includes>
    </configuration>
</plugin>

答案 1 :(得分:-1)

JUnit 5插件版本2.19不支持

maven.surefire,因此,如果需要使用自定义providerengine,请向插件添加自定义<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <dependencies> <dependency> <groupId>org.junit.platform</groupId> <artifactId>junit-platform-surefire-provider</artifactId> <version>1.3.1</version> </dependency> <dependency> <groupId>org.junit.jupiter</groupId> <artifactId>junit-jupiter-engine</artifactId> <version>5.3.1</version> </dependency> </dependencies> <configuration> <includes> <include>**/*Tests.java,**/*Test.java</include> </includes> </configuration> </plugin> JUnit 5版本。

赞:

[
{genderAge: "Male 25-39", count: 13029, weightedCount: 18475.6824262314, matchingSegment: 2},
{genderAge: "Female 55+", count: 35639, weightedCount: 32294.5926147014, matchingSegment: 8},
{genderAge: "Female 25-39", count: 23285, weightedCount: 20645.0599977815, matchingSegment: 6},
{genderAge: "Female 18-24", count: 7745, weightedCount: 8497.30029399032, matchingSegment: 5},
{genderAge: "Male 55+", count: 38018, weightedCount: 28589.2793936886, matchingSegment: 4},
{genderAge: "Male 18-24", count: 4038, weightedCount: 8122.65161312996, matchingSegment: 1},
{genderAge: "Female 40-54", count: 23051, weightedCount: 22834.3167597392, matchingSegment: 7},
{genderAge: "Male 40-54", count: 17278, weightedCount: 19681.8852663563, matchingSegment: 3}
]

您的 searchListingById(categoryId: number): Observable<any> { if(categoryId == 0 || categoryId == undefined){ return this.getListings().delay(100) }else{ return this.http.get( this.searchCatUrl+categoryId).delay(100); } } 的确切版本当然可能会有所不同,因此请注意版本号。