![](/img/trans.png)
[英]Maven will not find junit tests to execute, says it ran 0 tests and the build succeeded
[英]Execute Junit tests using Maven
我在src / test / java下有两个要运行的类: scen1.class
和scen2.class
。 这两个都有@Test
注释方法。
我有一个称为另一个类JunitDefinitions.class
一个只有@Before
, @After
, @BeforeClass
和@AfterClass
方法(无@Test)。 这也在src / test / java下,但是在不同的软件包下。
假设我具有默认的pom.xml
,我应该在其中添加什么才能执行所有这三个类?
<includes>
的配置,因为它中描述真实文档 。 默认情况下,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".
除了将您的类重命名为@viniciusartur所建议的Scen1Test.java和Scen2Test.java之类的名称外,这还将有助于Maven识别测试类以使用surefire-plugin执行它们。
这里要注意的另一点是,由于其中的原因@Before
, @BeforeClass
, @After
等不无独立执行@Test
方法是,只有
Test注释告诉JUnit, 可以将它附加到的public void方法作为测试用例运行 。 为了运行该方法,JUnit首先构造一个新的类实例,然后调用带注释的方法。
使用@Before注释公共void方法会使该方法在Test方法之前运行。 超类的@Before方法将在当前类的方法之前运行。
因此可以推断,在处理注释时,如果/src/test/java
下的类中不存在@Test注释(相对于基于maven的问题),则没有其他有意义的注释需要处理。
只是要注意,如果使用包含@Test method
另一个SubClassTest.java扩展此类,则将执行所有这些方法。 由于它们是根据对( @Test
)进行处理而处理的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.