我们有一个纯JUnit-5项目,我们想分类我们的单元测试。
要做到这一点,我理解的是我们需要包括JUnit-4 @RunWith(JUnitPlatform.class)。
import org.junit.platform.runner.JUnitPlatform;
import org.junit.platform.suite.api.IncludeTags;
import org.junit.platform.suite.api.SelectPackages;
import org.junit.runner.RunWith;
@RunWith(JUnitPlatform.class)
@SelectPackages("my.project.domain")
@IncludeTags("long-running-test")
public interface LongRunningTestSuite {}在Intellij中,我可以毫无问题地运行所有或仅仅测试套件,但是在使用maven执行时会出现一个错误:
这没什么用:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skip>false</skip>
<excludes>
<exclude>**/*TestSuite.java</exclude>
</excludes>
<includes>
<include>**/*Test.java, **/*IT.java</include>
</includes>
</configuration>
</plugin>如果我只是删除所有的XyzTestSuite.java类,那么maven构建就成功了。我还试过<exclude>my.project.domain.testsuite</exclude>。
排除缝不起作用。为什么?
发布于 2021-09-21 13:49:18
JUnitPlatform已经被否决了。
相应的新特性是JUnit平台套件引擎:https://junit.org/junit5/docs/current/user-guide/index.html#junit-platform-suite-engine
但是,如果仅仅是对测试进行分类,那么标记就足够了,这就足够了:https://junit.org/junit5/docs/current/user-guide/index.html#writing-tests-tagging-and-filtering
https://stackoverflow.com/questions/69269641
复制相似问题