This is wrapper for standard unittest library for Python with custom TestRunner to run test suites.
The main argument that this library was published is that standard unittest TestCase need test method prefix.
This way with TestCase method prefix introduce the noise and if you have a lot small test methods in TestCase
class then you still read test, and you are not focused on what do the test should test.
I prefer the @test
decorator or other solutions out of test method name to tell Your tests which method
is registered as test in test runner, then You can focused to read method as poetry not as technical layer.
This library contains tool called pyunit
to:
- initiate the configuration file for suites
- run tests automatically by
pyunit run
from command line
user@host $ pip install pytheons.pyunit
user@host $ pyunit
--------------------------------------------------
PyUnit - unittest test runner based on annotation.
Usage: pyunit COMMAND --OPTION <argument>
pyunit config init [--path=<path>]
pyunit run [--suites=<suites>]
pyunit (-h | --help)
pyunit --version
Commands:
config - Configuration sub-system
suites - Tests Suites sub-system
run - Test runner from CLI
Options:
-h --help Show this screen.
--version Show version.
- Create the configuration by command
pyunit config init [--path=path_to_your_test_configuration_dir]
- Create
.py
file to run all your tests. Below is content for this file:from pytheons.pyunit.suites.test_runner import TestRunner TestRunner.run()
- Write or Reorganise Your tests in structure
test/<suite-name>/[optional subdir]/<test_name>.py
- Each test folder should be a package with
__init__.py
file - unittest throws exception that directory is notexecutable
orcallable
- Mark Your method by
@test
decorator from PyUnit libraryfrom unittest import TestCase from pytheons.pyunit.decorators.test import test class MyFirstTest(TestCase): @test def when_fuel_size_is_30_then_cost_should_be_300(self): fuel = 30 self.assertEqual(300, FuelCalcuator.calculate(fuel))
- Run test by
pyunit run
or run.py
file to run all tests
--suites
argument forpyunit run
andtest suites runner