netbeans - NetBeans Junit5 测试输出忽略 DisplayName 嵌套格式
问题描述
我没有从注释“@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 插件版本@Display
中添加了对注解的支持。此外,您需要配置参数和扩展名以允许 NetBeans 正确匹配显示名称。3.0.0.0-M4
statelessTestsetReporter
statelessTestsetInfoReporter
所以目前(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 不支持在测试结果窗口中对测试结果进行嵌套分组。可能最好为此类测试使用不同的类而不是嵌套类。
推荐阅读
- r - Step_dummy。处理由 recipe() 步骤生成的重复列名,Tidymodels
- javascript - 我可以将 HTML 属性传递给 *ngIf 中的函数吗?
- excel - VBA "Variable required. Can't assign to this expression" error - Goal-seek analysis
- javascript - 通过纯 Javascript 使用类、标题、段落、编号和删除按钮在单击时创建 div
- database - 通过 hyper 使用 mongoDB 的设置不起作用
- flutter - 横幅 Google 广告未显示 - 广告加载失败:LoadAdError(代码:3,域:com.google.android.gms.ads,消息:无广告配置。)
- c# - 在 Entity Framework 6 下工作的查询在 .Net5 中不起作用
- java - 使用 BroadcastReceiver 传递数据时出错
- vue.js - 单独的登录组件而不是处理组件 vuejs
- python - 如何通过python删除最后一个\n\n\n\n之后的行