JUnit 报告——测试方法描述
我想看看是否有办法通过 javadoc 在我的 junit 报告中包含“描述性文本”。 JUnit 4 似乎不像 TestNG 那样支持 @Test 注释的“描述”属性。
到目前为止,根据我的研究,只有一种名为 javadoc-junit 的工具(http://javadoc-junit .sourceforge.net/)。 但是我无法让它工作,因为它似乎与 Junit 4 不兼容。
我想要的是某种方式在 JUnit 报告中为我的每个测试方法提供一两句话文本。 JavaDoc 不好,因为目标受众必须在 JavaDoc 和 Junit Report 之间切换才能查看文档和/或测试统计数据。
有人知道我可以毫不费力地使用其他任何东西吗?
最好的, 雷杰
I am trying to see if there is a way to include "descriptive text" in my junit reports by way of javadocs. JUnit 4 doesnt seem to support the 'description' attribute for the @Test annotation like TestNG does.
So far from what I have researched there is only one tool out there called javadoc-junit (http://javadoc-junit.sourceforge.net/). However I could not get this to work since it seems to be incompatible with Junit 4.
What I want is some way to provide a sentence or two of text with my each test method in the JUnit report. JavaDoc is no good since the target audience will have to swtich between JavaDoc and the Junit Report to see documentation and/or test stats.
Anyone know of anything else I could use with minimal effort?
Best,
Ray J
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
在
JUnit 5
中,有一种方法可以使用@DisplayName
注释每个测试。 声明的测试类可以包含文本
、特殊字符
和表情符号
。每个测试的声明文本对
测试运行者
和测试报告
可见。Javadoc 说:
public @interface DisplayName
以及用户指南:
In
JUnit 5
there is a way to annotate every test with a@DisplayName
. The declared test classes can havetext
,special characters
andemojis
.The declared text on each test is visible by
test runners
andtest reports
.The Javadoc says:
public @interface DisplayName
And the User Guide:
还有一个相当新的解决方案,称为Allure。 那是一个基于Java的测试执行报告,主要是在代码中添加补充注释。 现有注释包括:
查看他们的wiki 和 示例项目 了解更多细节。
There's also rather recent solution called Allure. That's a Java-based test execution report mainly based on adding supplementary annotations to the code. Existing annotations include:
See their wiki and example project for more details.
我不会将 javadoc 放入 JUnit 测试中。 我通常使方法的名称具有足够的描述性,因此它与我能想到的任何评论一样好,甚至更好。
I don't put javadocs in JUnit tests. I usually make the name of the method descriptive enough so it's as good as or better than any comment I could come up with.
我可以想象,集成测试框架 (FIT) 将是一个很好且干净的解决方案。
FIT 做什么?
FIT 是一个框架,允许通过 Word 文档中的表格、wiki 表格或 html 表格编写测试。
FIT 会忽略表格之外的每个字符,并让您输入文档、描述、要求等。
这些表看起来怎么样?
想象一个函数
MyMath.square(int)
,它计算输入参数的平方。 您必须构建一个所谓的 Fixture,作为MyMath
和下表之间的适配器:第一列描述输入值,第二列描述预期结果。 如果不相等,则该字段标记为红色。
灯具是什么样的?
对于给定的示例,这将是正确的装置:
也许您可以使用 FIT 来满足您的要求。
请随意评论我的答案或编辑您的问题以获取更多信息!
I could imagine, that the Framework for Integrated Tests (FIT) would be a nice and clean solution.
What does FIT do?
FIT is a framework that allows to write tests via a table in a Word document, a wiki table or an html table.
Every character outside of a table is ignored by FIT and let you enter documentation, description, requirements and so on.
How does on of these tables look like?
Imagine a function
MyMath.square(int)
that squares it's input parameter. You have to build a so called Fixture, being an adapter between yourMyMath
and the following table:The first column describes input values, the second the expected result. If it's not equal, this field is marked as red.
How does a Fixture look like?
For the given example, this would be the correct fixture:
Probably, you can use FIT for your requirements.
Feel free to comment my answer or edit your question for more information!