NetBeans Junit5 测试输出忽略显示名称嵌套格式
NetBeans Junit5 Tests-Output ignore DisplayName Nested-Format
我没有从注释“@DisplayName”中获取名称作为 NetBeans 中的测试结果。仅显示测试函数的名称。嵌套测试的分组显示也被忽略
源代码
@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 中的测试显示显示 DisplayNames 并使用嵌套分组?
NetBeans 版本:12.0
Java 版本:11 (OpenJDK)
Maven 在 surefire 插件的 3.0.0.0-M4
version 中添加了对 @Display
注释的支持。此外,您需要配置 statelessTestsetReporter
和 statelessTestsetInfoReporter
扩展的参数以允许 NetBeans 正确匹配显示名称。
所以目前(01.2021),可以使用3.0.0.0-M4
或更高版本的surefire插件,JUnit版本应在5.5.2以上。类似的东西应该可以工作:
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>
<configuration>
<statelessTestsetReporter implementation="org.apache.maven.plugin.surefire.extensions.junit5.JUnit5Xml30StatelessReporter">
<version>3.0</version>
<usePhrasedFileName>true</usePhrasedFileName>
<usePhrasedTestSuiteClassName>true</usePhrasedTestSuiteClassName>
<usePhrasedTestCaseClassName>true</usePhrasedTestCaseClassName>
<usePhrasedTestCaseMethodName>true</usePhrasedTestCaseMethodName>
</statelessTestsetReporter>
<statelessTestsetInfoReporter implementation="org.apache.maven.plugin.surefire.extensions.junit5.JUnit5StatelessTestsetInfoReporter">
<usePhrasedClassNameInRunning>true</usePhrasedClassNameInRunning>
</statelessTestsetInfoReporter>
<properties>
<configurationParameters>
junit.jupiter.conditions.deactivate = *
junit.jupiter.extensions.autodetection.enabled = true
junit.jupiter.testinstance.lifecycle.default = per_class
</configurationParameters>
</properties>
</configuration>
</plugin>
</plugins>
我的情况如下:
@DisplayName("Display Name of class")
public class testClassSimple {
@Test
@DisplayName("Display name of method 1")
public void testMethod1() {
}
@Test
@DisplayName("Display name of method 2")
public void testMethod2() {
}
}
关于嵌套分组和@Nested
注解,目前NetBeans不支持在测试结果window中对测试结果进行嵌套分组。对于此类测试,最好使用不同的 类 而不是嵌套 类.
我没有从注释“@DisplayName”中获取名称作为 NetBeans 中的测试结果。仅显示测试函数的名称。嵌套测试的分组显示也被忽略
源代码
@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 中的测试显示显示 DisplayNames 并使用嵌套分组?
NetBeans 版本:12.0 Java 版本:11 (OpenJDK)
Maven 在 surefire 插件的 3.0.0.0-M4
version 中添加了对 @Display
注释的支持。此外,您需要配置 statelessTestsetReporter
和 statelessTestsetInfoReporter
扩展的参数以允许 NetBeans 正确匹配显示名称。
所以目前(01.2021),可以使用3.0.0.0-M4
或更高版本的surefire插件,JUnit版本应在5.5.2以上。类似的东西应该可以工作:
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>
<configuration>
<statelessTestsetReporter implementation="org.apache.maven.plugin.surefire.extensions.junit5.JUnit5Xml30StatelessReporter">
<version>3.0</version>
<usePhrasedFileName>true</usePhrasedFileName>
<usePhrasedTestSuiteClassName>true</usePhrasedTestSuiteClassName>
<usePhrasedTestCaseClassName>true</usePhrasedTestCaseClassName>
<usePhrasedTestCaseMethodName>true</usePhrasedTestCaseMethodName>
</statelessTestsetReporter>
<statelessTestsetInfoReporter implementation="org.apache.maven.plugin.surefire.extensions.junit5.JUnit5StatelessTestsetInfoReporter">
<usePhrasedClassNameInRunning>true</usePhrasedClassNameInRunning>
</statelessTestsetInfoReporter>
<properties>
<configurationParameters>
junit.jupiter.conditions.deactivate = *
junit.jupiter.extensions.autodetection.enabled = true
junit.jupiter.testinstance.lifecycle.default = per_class
</configurationParameters>
</properties>
</configuration>
</plugin>
</plugins>
我的情况如下:
@DisplayName("Display Name of class")
public class testClassSimple {
@Test
@DisplayName("Display name of method 1")
public void testMethod1() {
}
@Test
@DisplayName("Display name of method 2")
public void testMethod2() {
}
}
关于嵌套分组和@Nested
注解,目前NetBeans不支持在测试结果window中对测试结果进行嵌套分组。对于此类测试,最好使用不同的 类 而不是嵌套 类.