我在 src/test/java 下有 2 个类想要运行:scen1.class
和 scen2.class
。这两个都有 @Test
带注释的方法。
我有另一个名为 JunitDefinitions.class
的类,它只有 @Before
、@After
、@BeforeClass
和@AfterClass 方法(无@Test)。
这也在 src/test/java 下,但在不同的包下。
假设我有默认的 pom.xml
,我应该向其中添加什么才能执行所有这 3 个类?
最佳答案
- 将您的测试类重命名为 Scen1Test.java 和 Scen2Test.java 或使用
<includes>
包含 JunitFW.java、Scen1.java 和 Scen2.java配置,如 documentation 中所述. - JunitFW 类仅包含 @Before,因此不会将其检测为测试。您必须将 @Before 移至包含 @Test 的类,或在 JunitFW 类中包含 @Test 并将其重命名为 JunitFWTest 才能使其正常工作。
默认情况下,Surefire 插件将自动包含具有以下通配符模式的所有测试类:
"**/Test*.java" - includes all of its subdirectories and all Java filenames that start with "Test".
"**/*Test.java" - includes all of its subdirectories and all Java filenames that end with "Test".
"**/*Tests.java" - includes all of its subdirectories and all Java filenames that end with "Tests".
"**/*TestCase.java" - includes all of its subdirectories and all Java filenames that end with "TestCase".
关于java - 使用 Maven 执行 Junit 测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44216310/