Search code examples
rubytestunitrest-client

Creating a test report using Ruby unit test


I have a working testsuite which tests some RESTful API's. Up until now the stdout results have been fine:

.......E..F..

However now I need something a bit more informative.

The output should be:

TestName, startTime, endTime, Result

I'll probably write this to a file in csv or xml. Now, I'm having no problems with the test name, start time and end time (multiple ways to do this) but I don't know how to write the result, the . or F or E to the file.

Is there any way I can extract the test result and do something with it within the test or test runner?

Could someone point me in the right direction?


Solution

  • One alternative - simple - is to work with the output provided using command line string manipulation tools (sed/awk/..) and generate the required output format.

    A more involved alternative would be to dig into the test-unit internals and create your own test-runner which gives the required output. The ./lib/test/unit/ui/console/testrunner.rb file would be a good place to start.

    Check out https://stackoverflow.com/a/10558600/429758 for an example of how to write a customized test runner.