All Projects → oldani → Htmltestrunner

oldani / Htmltestrunner

Licence: mit
A Test Runner in python, for Human Readable HTML Reports

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to Htmltestrunner

bron
🏃‍♂️ Fast & tiny test runner for Node.js
Stars: ✭ 17 (-92.54%)
Mutual labels:  test-runner, testing-tools
Junit Dataprovider
A TestNG like dataprovider runner for JUnit with many additional features
Stars: ✭ 226 (-0.88%)
Mutual labels:  testing-tools, test-runner
Testfx
MSTest V2 framework and adapter
Stars: ✭ 391 (+71.49%)
Mutual labels:  testing-tools, test-runner
angular-karma test-explorer
vscode extension for easy angular testing and debugging
Stars: ✭ 67 (-70.61%)
Mutual labels:  test-runner, testing-tools
Zunit
A powerful testing framework for ZSH projects
Stars: ✭ 140 (-38.6%)
Mutual labels:  testing-tools, test-runner
Gorgon
Distributed testing for ruby with centralized management
Stars: ✭ 32 (-85.96%)
Mutual labels:  test-runner, testing-tools
Vstest
Visual Studio Test Platform is the runner and engine that powers test explorer and vstest.console.
Stars: ✭ 624 (+173.68%)
Mutual labels:  testing-tools, test-runner
eat
Json based scenario testing tool(which can have test for functional and non-functional)
Stars: ✭ 41 (-82.02%)
Mutual labels:  test-runner, testing-tools
Meissa
Cross-platform Distributed Test Runner. Executes tests in parallel, time balanced on multiple machines.
Stars: ✭ 66 (-71.05%)
Mutual labels:  testing-tools, test-runner
Cypress
Fast, easy and reliable testing for anything that runs in a browser.
Stars: ✭ 35,145 (+15314.47%)
Mutual labels:  testing-tools, test-runner
IO-TESTER
A functional test framework
Stars: ✭ 32 (-85.96%)
Mutual labels:  test-runner, testing-tools
Acutest
Simple header-only C/C++ unit testing facility.
Stars: ✭ 170 (-25.44%)
Mutual labels:  testing-tools, test-runner
ctest
A simple portable C test runner
Stars: ✭ 17 (-92.54%)
Mutual labels:  test-runner, testing-tools
Openrunner
Computest Openrunner: Benchmark and functional testing for frontend-heavy web applications
Stars: ✭ 16 (-92.98%)
Mutual labels:  test-runner, testing-tools
test junkie
Highly configurable testing framework for Python
Stars: ✭ 72 (-68.42%)
Mutual labels:  test-runner, testing-tools
Awesome Test Automation
A curated list of awesome test automation frameworks, tools, libraries, and software for different programming languages. Sponsored by http://sdclabs.com
Stars: ✭ 4,712 (+1966.67%)
Mutual labels:  testing-tools, test-runner
Pytest Ui
Text User Interface for running python tests
Stars: ✭ 23 (-89.91%)
Mutual labels:  testing-tools, test-runner
Nunit Console
NUnit Console runner and test engine
Stars: ✭ 168 (-26.32%)
Mutual labels:  testing-tools, test-runner
Specjour
distributed rspec & cucumber via bonjour
Stars: ✭ 214 (-6.14%)
Mutual labels:  testing-tools, test-runner
Hitchhiker
a Restful Api test tool
Stars: ✭ 2,175 (+853.95%)
Mutual labels:  testing-tools

HtmlTestRunner

Pypi link Travis job

HtmlTest runner is a unittest test runner that saves results in a human-readable HTML format.

This Package was inspired by unittest-xml-reporting and HtmlTestRunner by tungwaiyip and began by combining the methodology of the former with the functionality of the latter.

Table of Content

Installation

To install HtmlTestRunner, run this command in your terminal:

$ pip install html-testRunner

This is the preferred method to install HtmlTestRunner, as it will always install the most recent stable release. If you don't have pip installed, this Python installation guide can guide you through the process.

Usage:

With unittest.main()

import HtmlTestRunner
import unittest


class TestStringMethods(unittest.TestCase):
    """ Example test for HtmlRunner. """

    def test_upper(self):
        self.assertEqual('foo'.upper(), 'FOO')

    def test_isupper(self):
        self.assertTrue('FOO'.isupper())
        self.assertFalse('Foo'.isupper())

    def test_split(self):
        s = 'hello world'
        self.assertEqual(s.split(), ['hello', 'world'])
        # check that s.split fails when the separator is not a string
        with self.assertRaises(TypeError):
            s.split(2)

    def test_error(self):
        """ This test should be marked as error one. """
        raise ValueError

    def test_fail(self):
        """ This test should fail. """
        self.assertEqual(1, 2)

    @unittest.skip("This is a skipped test.")
    def test_skip(self):
        """ This test should be skipped. """
        pass

if __name__ == '__main__':
    unittest.main(testRunner=HtmlTestRunner.HTMLTestRunner())

Just import HtmlTestRunner from package, then pass it to unittest.main with the testRunner keyword. Tests will be saved under a reports/ directory by default (the output kwarg controls this.).

With Test Suites

HtmlTestRunner can also be used with test suites; just create a runner instance and call the run method with your suite. Here an example:

from unittest import TestLoader, TestSuite
from HtmlTestRunner import HTMLTestRunner
import ExampleTest
import Example2Test

example_tests = TestLoader().loadTestsFromTestCase(ExampleTest)
example2_tests = TestLoader().loadTestsFromTestCase(Example2Test)

suite = TestSuite([example_tests, example2_tests])

runner = HTMLTestRunner(output='example_suite')

runner.run(suite)

Combining Reports into a Single Report

By default, separate reports will be produced for each TestCase. The combine_reports boolean kwarg can be used to tell HTMLTestRunner to instead produce a single report:

import HtmlTestRunner
h = HtmlTestRunner.HTMLTestRunner(combine_reports=True).run(suite)

Setting a filename

By default the name of the HTML file(s) produced will be created by joining the names of each test case together. The report_name kwarg can be used to specify a custom filename. For example, the following will produce a report file called "MyReport.html":

import HtmlTestRunner
h = HtmlTestRunner.HTMLTestRunner(combine_reports=True, report_name="MyReport", add_timestamp=False).run(suite)

Console output:

Console output

This is an example of the console output expected when using HTMLTestRunner.

Test Result:

Test Results

This is a sample of the results from the template that came by default with the runner.

Custom Templates:

If you want to use your own template you can pass the absolute path when instantiating the HTMLTestRunner class using the template kwarg:

import HtmlTestRunner
h = HtmlTestRunner.HTMLTestRunner(template='path/to/template')

Your template must use jinja2 syntax, since this is the engine we use.

When using any template, the following variables will be available by default for use by jinja2:

  • title: This is the report title - by default this is "Unittests Results" but can be changed using the report_title kwarg
  • headers: This is a dict with 2 items:
    • start_time: A datetime object representing when the test was run
    • status: A dict of of the same form as the sub-dicts described below for summaries but for all tests combined
  • all_results: A dict - keys are the names of each test case and values are lists containing test result objects (see the source code or the template for what information these provide)
  • summaries: A dict - keys are the names of each test case and values are dicts containing:
    • total: The total number of tests
    • success: The number of passed tests
    • failure: The number of failed tests
    • error: The number of errored tests
    • skip: The number of skipped tests
    • duration: A string showing how long all these tests took to run in either seconds or milliseconds

Furthermore, you can provide any number of further variables to access from the template using the template_args kwarg. For example, if you wanted to have the name of the logged in user available to insert into reports that could be achieved as follows:

import getpass
import HtmlTestRunner

template_args = {
    "user": getpass.getuser()
}
h = HtmlTestRunner.HTMLTestRunner(template='path/to/template', template_args=template_args)

Now the user name can be accessed from a template using jinja2 syntax: {{ user }}.

Click here for a template example, this is the default one shipped with the package.

TODO

  • [ ] Add Test
  • [ ] Improve documentation
  • [x] Add custom templates
  • [ ] Add xml results
  • [ ] Add support for Python2.7
  • [x] Add support for one report when running test suites.

Contributing

Contributions are welcome, and they are greatly appreciated! Every little bit helps, and credit will always be given.

For more info please click here

Credits

This package was created with Cookiecutter and the audreyr/cookiecutter-pypackage project template.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].