June 29, 2010 0

Automatic Test Reporting, HTMLified

By Anthony in Python, QA, Selenium, Test Automation, Testing

When running tests of any kind, it’s always good to have a report for your records or to show other people.

I used HTMLTestRunner, and found it to be very helpful for creating a logical, and concise report.

When I build picka, i have a series of tests that execute each function inside. The output, is now piped to an html file, which can be viewed here:

Picka Results

This report is automatically created using the snippet below (and the module HTMLTestRunner). Using the code below allows us to automatically generate very nice looking, HTML unittest results reports.

if __name__ == "__main__":
    suite = unittest.TestSuite()
    loader = unittest.TestLoader()
    browser_suite = loader.loadTestsFromTestCase(TestCases)
    suite.addTest(browser_suite)
    fp = file('results.html', 'wb')
    runner = HTMLTestRunner.HTMLTestRunner(
        stream = fp,
        title = 'Picka Test',
        description = str(time.strftime("%I:%M:%S %p", time.localtime())) + ' - Version 0.1a',
        )