gpt4 book ai didi

JUnit 报告——测试方法描述

转载 作者:行者123 更新时间:2023-12-03 10:42:20 31 4
gpt4 key购买 nike

我想看看是否有办法通过 javadoc 在我的 junit 报告中包含“描述性文本”。 JUnit 4 似乎不像 TestNG 那样支持 @Test 注释的“描述”属性。

到目前为止,我所研究的只有一种工具叫做 javadoc-junit ( http://javadoc-junit.sourceforge.net/ )。但是我无法让它工作,因为它似乎与 Junit 4 不兼容。

我想要的是在 JUnit 报告中为我的每个测试方法提供一两句文本的方法。 JavaDoc 不好,因为目标受众必须在 JavaDoc 和 Junit 报告之间切换才能查看文档和/或测试统计信息。

任何人都知道我可以用最少的努力使用的其他东西吗?

最好的事物,
雷杰

最佳答案

JUnit 5有一种方法可以用 @DisplayName 注释每个测试.声明的测试类可以有 text , special charactersemojis .

每个测试中声明的文本通过 test runners 可见和 test reports .

Javadoc说:
public @interface 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.



User Guide :
import org.junit.gen5.api.DisplayName;
import org.junit.gen5.api.Test;

@DisplayName("A special test case")
class DisplayNameDemo {

@Test
@DisplayName("Custom test name containing spaces")
void testWithDisplayNameContainingSpaces() {
}

@Test
@DisplayName("╯°□°)╯")
void testWithDisplayNameContainingSpecialCharacters() {
}

@Test
@DisplayName("😱")
void testWithDisplayNameContainingEmoji() {
}
}

关于JUnit 报告——测试方法描述,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/775096/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com