All Projects → zuo → unittest_expander

zuo / unittest_expander

Licence: MIT license
A library that provides flexible and easy-to-use tools to parameterize Python unit tests, especially those based on unittest.TestCase.

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to unittest expander

TestIt
Generate unit testing boilerplate from kotlin files.
Stars: ✭ 32 (+166.67%)
Mutual labels:  unit-testing, unittest, unit-tests, unit-test
Capture Stream
Capture stream output.
Stars: ✭ 10 (-16.67%)
Mutual labels:  unit-testing, test, tests, unittest
Wasmite
Now WebAssembly has proper testing, unit-testing and debugging 🤗
Stars: ✭ 20 (+66.67%)
Mutual labels:  unit-testing, test, unittest
Testify
A unit testing framework written in bash for bash scripts
Stars: ✭ 45 (+275%)
Mutual labels:  test, unittest, unit-test
goreporter
A Golang tool that does static analysis, unit testing, code review and generate code quality report.
Stars: ✭ 3,019 (+25058.33%)
Mutual labels:  unit-testing, test, unit-test
Kotlinmvparchitecture
Clean MVP Architecture with Dagger2 + Retrofit2 + Mockito + Fresco + EasiestGenericRecyclerAdapter using Kotlin. Added Unit Tests(Kotlin Tests)!
Stars: ✭ 143 (+1091.67%)
Mutual labels:  unit-testing, unittest, unit-test
ionic-workflow-guide
Create a full and powerful worflow with Ionic (Unit Testing, Environment variables, Automatic documentation, Production App Server, Automatic deployment)
Stars: ✭ 46 (+283.33%)
Mutual labels:  unit-testing, unit-tests, unit-test
Goreporter
A Golang tool that does static analysis, unit testing, code review and generate code quality report.
Stars: ✭ 2,943 (+24425%)
Mutual labels:  unit-testing, test, unit-test
Nunit cshaprp cheatsheet
Example implementations of each attribute available in Nunit2 unit Testing Framework using C# .NET.
Stars: ✭ 14 (+16.67%)
Mutual labels:  unit-testing, unittest, unit-test
EntityFrameworkCore.AutoFixture
A library aimed to minimize the boilerplate required to unit-test Entity Framework Core code using AutoFixture and in-memory providers.
Stars: ✭ 31 (+158.33%)
Mutual labels:  unit-testing, tests, unit-test
mockingbird
🐦 Decorator Powered TypeScript Library for Creating Mocks
Stars: ✭ 70 (+483.33%)
Mutual labels:  test, unit-test
arduino-ci-script
Bash script for continuous integration of Arduino projects
Stars: ✭ 25 (+108.33%)
Mutual labels:  test, tests
lwc-test
LWC plugins and utilities for testing
Stars: ✭ 39 (+225%)
Mutual labels:  test, unit-test
pytest
The pytest framework makes it easy to write small tests, yet scales to support complex functional testing
Stars: ✭ 9,731 (+80991.67%)
Mutual labels:  unit-testing, test
eat
Json based scenario testing tool(which can have test for functional and non-functional)
Stars: ✭ 41 (+241.67%)
Mutual labels:  unit-testing, test
Caraya
Assertion and unit test framework for LabVIEW
Stars: ✭ 45 (+275%)
Mutual labels:  unit-testing, test
telenium
Automation for Kivy Application
Stars: ✭ 56 (+366.67%)
Mutual labels:  tests, unittest
laziest
Work in Progress: Package that trying to generate unit tests from code
Stars: ✭ 18 (+50%)
Mutual labels:  tests, unittest
phpunit-injector
Injects services from a PSR-11 dependency injection container to PHPUnit test cases
Stars: ✭ 62 (+416.67%)
Mutual labels:  test, tests
mutode
Mutation testing for JavaScript and Node.js
Stars: ✭ 61 (+408.33%)
Mutual labels:  test, tests

unittest_expander is a Python library that provides flexible and easy-to-use tools to parameterize your unit tests, especially those based on unittest.TestCase.

The library is compatible with Python 2.7, 3.5, 3.6, 3.7, 3.8, 3.9 and 3.10, and does not depend on any external packages (i.e., uses only the Python standard library).

Authors:Jan Kaliszewski (zuo) and others...
License:MIT License
Home Page:https://github.com/zuo/unittest_expander
Documentation:https://unittest-expander.readthedocs.io/en/stable/

Installing

The easiest way to install the library is to execute (preferably in a virtualenv) the command:

python -m pip install unittest_expander

(note that you need network access to do it this way). If you do not have the pip tool installed -- see: https://packaging.python.org/guides/installing-using-pip-and-virtual-environments/

Alternatively, you can download the library source archive, unpack it, cd to the unpacked directory and execute (preferably in a virtualenv) the following command:

python -m pip install .

Note: you may need to have administrator privileges if you do not operate in a virtualenv.

It is also possible to use the library without installing it: as its code is contained in a single file (unittest_expander.py), you can just copy it into your project.

Usage example

Consider the following ugly test:

import unittest

class Test(unittest.TestCase):
    def test_sum(self):
        for iterable, expected in [
            ([], 0),
            ([0], 0),
            ([3], 3),
            ([1, 3, 1], 5),
            (frozenset({1, 3}), 4),
            ({1:'a', 3:'b'}, 4),
        ]:
            self.assertEqual(sum(iterable), expected)

Is it cool? Not at all! So let's improve it:

import unittest
from unittest_expander import expand, foreach

@expand
class Test(unittest.TestCase):
    @foreach(
        ([], 0),
        ([0], 0),
        ([3], 3),
        ([1, 3, 1], 5),
        (frozenset({1, 3}), 4),
        ({1:'a', 3:'b'}, 4),
    )
    def test_sum(self, iterable, expected):
        self.assertEqual(sum(iterable), expected)

Now you have 6 distinct tests (properly isolated and being always reported as separate tests), although they share the same test method source.

You may want to do the same in a bit more verbose and descriptive way:

import unittest
from unittest_expander import expand, foreach, param

@expand
class Test(unittest.TestCase):

    test_sum_params = [
        param([], expected=0).label('empty gives 0'),
        param([0], expected=0),
        param([3], expected=3),
        param([1, 3, 1], expected=5),
        param(frozenset({1, 3}), expected=4),
        param({1:'a', 3:'b'}, expected=4).label('even dict is ok'),
    ]

    @foreach(test_sum_params)
    def test_sum(self, iterable, expected):
        self.assertEqual(sum(iterable), expected)

This is only a fraction of the possibilities unittest_expander offers to you.

You can learn more from the actual documentation of the module.

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].