在NetBeans中,我没有从标注“@DisplayName”中获取名称作为测试结果。只显示测试函数的名称。嵌套测试的分组显示也被忽略。
源代码
@DisplayName("test facade")
public class TestFacadeTest {
@BeforeAll
public static void setUpClass() {
}
@AfterAll
public static void tearDownClass() {
}
@BeforeEach
public void setUp() {
}
@AfterEach
public void tearDown() {
}
@Test
@DisplayName("senseless test")
public void test(){
Assertions.assertTrue(true);
}
@Nested
@DisplayName("tests - compareStringNullSave")
class CompateStringNullSaveTestGroup {
@BeforeEach
public void setUp() {
}
@Test
@DisplayName("both identical")
public void Test1(){
String str1 = "Test123";
String str2 = "Test123";
Assertions.assertTrue(TestFacade.compareStringNullSave(str1, str2));
Assertions.assertTrue(TestFacade.compareStringNullSave(str2, str1));
}
@Test
@DisplayName("Identical text but different uppercase and lowercase letters")
public void Test2(){
String str1 = "Test123";
String str2 = "test123";
Assertions.assertFalse(TestFacade.compareStringNullSave(str1, str2));
Assertions.assertFalse(TestFacade.compareStringNullSave(str2, str1));
}
}
}
从pom.xml中提取
<dependencies>
[...]
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.7.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<version>5.7.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.7.0</version>
<scope>test</scope>
</dependency>
[...]
</dependencies>
<build>
<plugins>
[...]
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
<configuration>
<properties>
<configurationParameters>
junit.jupiter.conditions.deactivate = *
junit.jupiter.extensions.autodetection.enabled = true
junit.jupiter.testinstance.lifecycle.default = per_class
</configurationParameters>
</properties>
</configuration>
</plugin>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.22.2</version>
</plugin>
</plugins>
</build>
我必须进行什么设置才能使NetBeans中的测试显示显示DisplayName并使用嵌套分组?
NetBeans版本:12.0 Java版本:第11页(开放式JDK)
1条答案
按热度按时间nkkqxpd91#
Maven在surefire插件的
3.0.0.0-M4
版本中添加了对@Display
注解的支持。此外,您需要配置statelessTestsetReporter
和statelessTestsetInfoReporter
扩展的参数,以允许NetBeans正确匹配显示名称。因此,目前(2021年1月),您可以使用
3.0.0.0-M4
或更高版本的surefire插件,JUnit的版本应该高于5.5.2。下面是我的案例:
对于嵌套分组和
@Nested
注解,NetBeans目前还不支持在测试结果窗口中对测试结果进行嵌套分组。对于这样的测试,使用不同的类可能比使用嵌套类更好。