是否可以在 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/