tags:

views:

626

answers:

1

I am using the ant tasks 'junit' and 'junitreport' to run my JUnit Tests and generate a report at the end (=> "Unit Test Results").

Is it there some easy way to extend this output somehow to get more information displayed in the report? For example to add an additional column which contains link to a screenshot taken by the test.

I've seen that one could write an own ant junit test runner like the EclipseTestRunner but this is quite some effort. Is there no API to access the elements of a unit report?

+3  A: 
Jukka Matilainen
Hi, I don't want to apply a different style to my report. I need to extend the report by additional (custom) information. So I have to be able to somehow modify the data of the report, not its style. Thanks.
blackicecube
The source data for the report produced by the `junitreport` task comes from the XML files generated by the `junit` task. However, based on that data you can add some some extra information to the report. -- For example, if your unit tests produce screenshots in some known location with names that can be derived from the unit test names, it is possible to create links to them by customizing the report style, as in the example above. (I edited the answer to add a screenshot of the end result.)
Jukka Matilainen
Thanks for your proposition! That's a good approach as start. It's just that I have not only 1 single screenshot per test method but several screenshots, depending on what is tested. So the screenshots are numbered and named, e.g. TestClass-testMethod-01.png.Is there a way with XSLT to "count" the number of screenshots on the file system which "belong" to the test method?.
blackicecube
Accessing the file system from XSLT is not really feasible without using extensions. About the only format that is accessible from XSLT 1 is (not surprisingly) XML. Three options that come to my mind at the moment, ranging from the one requiring the least programming to the one requiring the most: ...
Jukka Matilainen
... (1) Put the screenshots into separate directories per test. Then, instead of linking directly to the screenshot, link to the directory.
Jukka Matilainen
... or (2) in your Ant build file, generate an XML file listing the screenshots from the file system and access that XML file from XSLT using the `document()` function.
Jukka Matilainen
... or (3) Using the `classname` attribute of the `formatter` of the `junit` task, specify your own formatter which includes the information about screenshots in the generated XML. Suppose that your unit tests output the names of the screenshots it creates. I guess it might be possible to extend the default `XMLJUnitResultFormatter` to inspect the output from each test, and write out additional XML tags for each screenshot detected from the output. http://svn.apache.org/viewvc/ant/core/tags/ANT_171/src/main/org/apache/tools/ant/taskdefs/optional/junit/XMLJUnitResultFormatter.java?view=markup
Jukka Matilainen