Coder Social home page Coder Social logo

michalsvagerka / xmlrunner Goto Github PK

View Code? Open in Web Editor NEW

This project forked from pycontribs/xmlrunner

0.0 2.0 0.0 227 KB

unittest-based test runner with Ant/JUnit like XML reporting.

License: GNU Lesser General Public License v3.0

Makefile 3.98% Shell 6.48% Python 89.54%

xmlrunner's Introduction

unittest-xml-reporting

unittest-xml-reporting is a unittest test runner that can save test results to XML files that can be consumed by a wide range of tools, such as build systems, IDEs and continuous integration servers.

If you find a bug the best way to have it fixed is to fix it yourself and to make a pull request.

If you want you can even get direct access to the repository, is always better to have more than one maintainer.

Requirements

  • Python 2.7+

Installation

The easiest way to install unittest-xml-reporting is via Pip:

$ pip install unittest-xml-reporting

If you use Git and want to get the latest development version:

$ git clone git://github.com/danielfm/unittest-xml-reporting.git
$ cd unittest-xml-reporting
$ sudo python setup.py install

Or get the latest development version as a tarball:

$ wget http://github.com/danielfm/unittest-xml-reporting/tarball/master
$ tar zxf danielfm-unittest-xml-reporting-XXXXXXXXXXXXXXXX.tar.gz
$ cd danielfm-unittest-xml-reporting-XXXXXXXXXXXXXXXX
$ sudo python setup.py install

Usage

The script below, adapted from the unittest, shows how to use XMLTestRunner in a very simple way. In fact, the only difference between this script and the original one is the last line:

import random
import unittest
import xmlrunner

class TestSequenceFunctions(unittest.TestCase):

    def setUp(self):
        self.seq = list(range(10))

    @unittest.skip("demonstrating skipping")
    def test_skipped(self):
        self.fail("shouldn't happen")

    def test_shuffle(self):
        # make sure the shuffled sequence does not lose any elements
        random.shuffle(self.seq)
        self.seq.sort()
        self.assertEqual(self.seq, list(range(10)))

        # should raise an exception for an immutable sequence
        self.assertRaises(TypeError, random.shuffle, (1,2,3))

    def test_choice(self):
        element = random.choice(self.seq)
        self.assertTrue(element in self.seq)

    def test_sample(self):
        with self.assertRaises(ValueError):
            random.sample(self.seq, 20)
        for element in random.sample(self.seq, 5):
            self.assertTrue(element in self.seq)

if __name__ == '__main__':
    unittest.main(testRunner=xmlrunner.XMLTestRunner(output='test-reports'))

Django

In order to plug XMLTestRunner to a Django project, add the following to your settings.py:

TEST_RUNNER = 'xmlrunner.extra.djangotestrunner.XMLTestRunner'

Also, the following settings are provided so you can fine tune the reports:

TEST_OUTPUT_VERBOSE (Default: 1)

Besides the XML reports generated by the test runner, a bunch of useful information is printed to the sys.stderr stream, just like the TextTestRunner does. Use this setting to choose between a verbose and a non-verbose output.

TEST_OUTPUT_DESCRIPTIONS (Default: False)

If your test methods contains docstrings, you can display such docstrings instead of display the test name (ex: module.TestCase.test_method). In order to use this feature, you have to enable verbose output by setting TEST_OUTPUT_VERBOSE = 2.

TEST_OUTPUT_DIR (Default: ".")

Tells the test runner where to put the XML reports. If the directory couldn't be found, the test runner will try to create it before generate the XML files.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.