java - JUnit 测试说明

标签 java testing junit

是否可以在 JUnit 中为 future 的读者添加一个简短的测试描述(例如,正在测试什么,一些简短的解释,预期的结果,......)?我的意思是在 ScalaTest 中,我可以在其中编写:

test("Testing if true holds") {
  assert(true)
}

理想的方法是使用一些注释,例如

@Test
@TestDescription("Testing if true holds")
public void testTrue() {
    assert(true);
}

因此,如果我使用 Maven(或其他类似工具)运行此类带注释的测试,我可以在使用 ScalaTest 时获得与 SBT 中类似的输出:

- Testing if entity gets saved correctly
- Testing if saving fails when field Name is not specified
- ...

目前我可以使用非常长的方法名称或编写 javadoc 注释,它们是 不存在于构建输出中。

谢谢。

最佳答案

在 JUnit 5 中,有 @DisplayName注释:

@DisplayName is used to declare a custom display name for the annotated test class or test method. Display names are typically used for test reporting in IDEs and build tools and may contain spaces, special characters, and even emoji.

例子:

@Test
@DisplayName("Test if true holds")
public void checkTrue() {
    assertEquals(true, true);
}

关于java - JUnit 测试说明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13159293/

相关文章:

在 Ruby on Rails 中测试非资源操作

java - 返回今天前N天的测试方法

java - 如何使用 junit 和 easymock 模拟静态方法

java - 在http :xalan:jar:2. eviware.com/repository/maven2/中找不到org.apache.xalan ://www. 7.1

java - 变量 x 可能尚未初始化?

java - Android 远程 XML 解析(文档生成器)

带接口(interface)的 PHPunit 模拟对象

java - GregorianCalendar 给出了 "Asia/Singapore"时区的意外结果,系统日期为 2014 年 1 月 30 日

在 Elm 中测试去抖动

java - 使用mockito模拟返回ByteBuffer的方法的响应