junit junit

JUnit @DisplayName annotation is used to provide a custom name for the test class and test methods. We can use spaces, special characters, and even emojis in the display name.

JUnit @DisplayName批注用于为测试类和测试方法提供自定义名称。 我们可以在显示名称中使用空格,特殊字符,甚至表情符号。

JUnit显示名称示例 (JUnit Display Name Example)

By default, JUnit reporting prints the class name and method name in the IDE test report. We can use @DisplayName to specify a custom name that is easy to read and provide information about the test class and method.

默认情况下, JUnit报告会在IDE测试报告中打印类名和方法名。 我们可以使用@DisplayName来指定一个易于阅读的自定义名称,并提供有关测试类和方法的信息。

Let’s see some examples of JUnit Jupiter @DisplayName annotation.

让我们看一些JUnit Jupiter @DisplayName批注的示例。

Display Name for Test Class

测试类别的显示名称

@DisplayName("MyTestClass")
public class DisplayNameTest {
}

Display Name for Methods

方法的显示名称

@Test
@DisplayName("Example Test Method with No Business Logic")
void test() {assertTrue(3 > 0);
}

Display Name with Emojis

显示名称和表情符号

@Test
@DisplayName("MyTestMethod ☺")
void test1(TestInfo testInfo) {assertEquals("MyTestMethod ☺", testInfo.getDisplayName());
}

Notice that we can get the Test method display name in the method by injecting TestInfo to the method argument.

注意,通过将TestInfo注入到方法参数中,可以在方法中获得Test方法的显示名称。

报表中的JUnit DisplayName (JUnit DisplayName in Reporting)

When we run our JUnit test class, we can see the display name in the JUnit view window.

运行JUnit测试类时,我们可以在JUnit视图窗口中看到显示名称。

摘要 (Summary)

JUnit Jupiter @DisplayName annotation doesn’t provide any testing benefits. However, it can be used to provide information about the test methods that show in reporting and can be understood easily by any non-technical user too.

JUnit Jupiter @DisplayName注释没有提供任何测试好处。 但是,它可以用来提供有关报告中显示的测试方法的信息,并且任何非技术用户也可以轻松理解。

GitHub Repository.GitHub Repository中检出完整的类和其他JUnit示例。

翻译自: https://www.journaldev.com/21674/junit-display-name-displayname

junit junit

junit junit_JUnit显示名称– @DisplayName相关推荐

  1. junit:junit_JUnit ExpectedException规则:超越基础

    junit:junit JUnit测试中有多种处理异常的方法. 正如我在以前的一篇文章中所写的那样 ,我最好的方法是使用org.junit.rules.ExpectedException规则. 基本上 ...

  2. junit junit_JUnit理论简介

    junit junit 您读过数学理论吗? 它通常读取如下内容: 对于所有a,b> 0满足以下条件:a + b> a和a + b> b 通常,这些语句更难以理解. 这种陈述有一些有趣 ...

  3. junit:junit_JUnit和Hamcrest:在assertEquals上进行改进

    junit:junit 在我的博客文章中,Java越来越接受静态导入吗? 在本文中,我讨论了在Java中越来越多地使用静态导入来使代码在某些情况下更加流畅. Java中的 单元测试特别受静态导入的影响 ...

  4. JUnit 5 –基础

    JUnit 5是适用于Java的下一代单元测试框架,具有许多有趣的功能,包括嵌套测试,参数化测试,新的扩展API或Java 8支持. 本文展示了JUnit 5的基本概念,包括测试生命周期,参数注入和断 ...

  5. Junit使用方法总结

    1-注解 区别于一般语言中的注释,程序运行时会根据注解,为标记注解的方法进行不同的操作,一般将注解写在测试方法的前面,常用的注解如下: @BeforeAll,这个注解的定义是使用了该注解的方法在当前整 ...

  6. junit注释_JUnit注释

    junit注释 JUnit testing framework is built on annotations. JUnit 5 is a major upgrade from JUnit 4. Th ...

  7. junit 重复测试多个类_JUnit重复测试– @RepeatedTest

    junit 重复测试多个类 JUnit Jupiter provides @RepeatedTest annotation that lets us repeat a test specified n ...

  8. JUnit5 快速指南

    JUnit5 快速指南 version: junit5 1. 安装 2. JUnit 注解 3. 编写单元测试 3.1. 基本的单元测试类和方法 3.2. 定制测试类和方法的显示名称 3.3. 断言( ...

  9. junit5和junit4_JUnit 5 –基础

    junit5和junit4 JUnit 5是适用于Java的下一代单元测试框架,具有许多有趣的功能,包括嵌套测试,参数化测试,新的扩展API或Java 8支持. 本文展示了JUnit 5的基本概念,包 ...

最新文章

  1. 「要拼就拼运维」5分钟一台?它让我爱上工作了!
  2. 从linux小白到进大厂,我是怎么做到的?
  3. 项目打包去掉调试时的NSLog、print
  4. 我的世界服务器物品属性,属性 - Minecraft Wiki,最详细的官方我的世界百科
  5. React开发(238):dva概念3action
  6. Redis:21---客户端相关配置篇
  7. 用groovy采集网页数据
  8. left join 多条件_第九篇|Spark的五种JOIN策略解析
  9. c语言中锁的作用,C语言中的多线程死锁
  10. ubuntu设置打开主目录(home文件夹)的快捷键
  11. BZOJ 1013: [JSOI2008]球形空间产生器sphere( 高斯消元 )
  12. 部署Django REST Framework服务(Nginx + uWSGI + Django)
  13. 带通滤波器中心频率带宽matlab,带通滤波器频率设置
  14. 下载ue5和古代山谷
  15. BusinessSkinForm VCL
  16. k8s教程(pod篇)-污点与容忍
  17. 13步设计出一个ITSM系统
  18. 国际贸易术语解释通则(DDP 完税后交货(……指定目的港))
  19. Pod进程内存缓存分析
  20. border样式失效原因

热门文章

  1. Ubuntu 左边栏和顶栏都不见了,ctrl+alt+t 也调用不出terminal
  2. 一个优秀的Android应用从建项目开始
  3. 数据库(.udl)简单测试连接
  4. candence 知识积累3
  5. 水晶报表提示“出现打印错误。将停止打印”的原因,非page_Init
  6. Windwows7 下安装mysql5
  7. [转载] 终于来了!TensorFlow 2.0入门指南(上篇)
  8. [转载] python3 numpy函数_Python numpy总结(3)——常用函数用法
  9. [转载] python怎么将十进制转换为二进制_python十进制和二进制的转换方法(含浮点数)
  10. 数据结构与算法(Python)第一天