JUnit测试报告富集的JavaDoc [英] JUnit test report enrichment with JavaDoc

查看:274
本文介绍了JUnit测试报告富集的JavaDoc的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有关我们需要生成集成测试不仅显示详细的测试报告客户,一切都是绿色的,而且测试做了什么。我的同事和我都懒的家伙,我们并不想破解小号preadsheets或文本文档。

For a customer we need to generate detailed test reports for integration tests which not only show, that everything is green, but also what the test did. My colleagues and I are lazy guys and we do not want to hack spreadsheets or text documents.

对于这一点,我想办法记录在每个@Test标注的方法,每个测试类JavaDoc注释更复杂的集成测试。对于测试的家伙是一个很好的帮助,看看哪个要求,吉拉票或任何测试链接到与测试实际上是尝试做什么。我们希望这些信息提供给我们的客户了。

For that, I think about a way to document the more complex integration tests with JavaDoc comments on each @Test annotated method and each test class. For the test guys it is a good help to see to which requirement, Jira ticket or whatever the test is linked to and what the test actually tries to do. We want to provide this information to our customer, too.

现在最大的问题是:我们如何能够把JavaDoc,以了解每个方法和每个测试类到JUnit的报告?我们使用JUnit 4.9和Maven。

The big question now is: How can we put the JavaDoc for each method and each test class into the JUnit reports? We use JUnit 4.9 and Maven.

我知道,有一个说明每个assertXXX(),但我们真的需要一个不错的HTML列表的结果,或列出所有类别的PDF文档,并有相关文件证明及以下的所有@Test方法及其说明,测试时间,结果,如果失败了,个中缘由。

I know, that there is a description for each assertXXX(), but we really would need a nice HTML list as result or a PDF document which lists all classes and there documentation and below that all @Test methods and their description, the testing time, the result and if failed, the reason why.

还是有另一种选择,产生奇特的测试脚本? (或者我们应该在这个启动项目开源!?;-))

Or is there another alternative to generate fancy test scripts? (Or should we start an OpenSource project on this!? ;-) )

更新:
我问如何添加一个RunListener到Eclipse有它在Eclipse还报告开始时,有一个问题。使用自定义的TestRunner提出的解决方案是另一种可能性,让测试结果报告。看看:如何使用在Eclipse JUnit的RunListener?

推荐答案

要实现这一目标的方法之一是使用自定义的<一个href=\"http://junit.sourceforge.net/javadoc/org/junit/runner/notification/RunListener.html\">RunListener,需要提醒的是这将是更容易使用的注释,而不是javadoc的。您将需要有一个自定义的注释,如:

One way to achieve this would be to use a custom RunListener, with the caveat that it would be easier to use an annotation rather than javadoc. You would need to have a custom annotation such as:

@TestDoc(text="tests for XXX-342, fixes customer issue blahblah")
@Test
public void testForReallyBigThings() {
    // stuff
}

RunListener 监听测试活动,如测试开始,测试结束后,测试失败,测试的成功等。

RunListener listens to test events, such as test start, test end, test failure, test success etc.

public class RunListener {
    public void testRunStarted(Description description) throws Exception {}
    public void testRunFinished(Result result) throws Exception {}
    public void testStarted(Description description) throws Exception {}
    public void testFinished(Description description) throws Exception {}
    public void testFailure(Failure failure) throws Exception {}
    public void testAssumptionFailure(Failure failure) {}
    public void testIgnored(Description description) throws Exception {}
}

描述的包含施加到测试方法注释的列表中,因此使用上面的例子可以用得到注解TestDoc:

Description contains the list of annotations applied to the test method, so using the example above you can get the Annotation TestDoc using:

description.getAnnotation(TestDoc.class);

和提取文本为正常。

您可以再使用 RunListener 来生成你想要的文件,与本试验的具体文本,该测试是否通过或失败,或者被忽略,时间拍摄等,这将是你的自定义报表。

You can then use the RunListener to generate the files you want, with the text specific to this test, whether the test passed or failed, or was ignored, the time taken etc. This would be your custom report.

然后,在万无一失的,你可以指定一个自定义的监听器,使用:

Then, in surefire, you can specify a custom listener, using:

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-surefire-plugin</artifactId>
  <version>2.10</version>
  <configuration>
    <properties>
      <property>
        <name>listener</name>
        <value>com.mycompany.MyResultListener,com.mycompany.MyResultListener2</value>
      </property>
  </configuration>
</plugin>

这是从<一个href=\"http://maven.apache.org/surefire/maven-surefire-plugin/examples/junit.html#Using_custom_listeners_and_reporters\">Maven神火插件,使用JUnit,使用自定义的听众和记者

该解决方案具有不必尽可能回车,格式化而言的javadoc的灵活性的缺点,但它确实有优点,即文档在一个特定地点,注解TestDoc

This solution has the disadvantage that you don't have the flexibility of javadoc as far as carriage returns, formatting is concerned, but it does have the advantage that the documentation is in one specific place, the annotation TestDoc.

这篇关于JUnit测试报告富集的JavaDoc的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆