Use native assertions to implement TDD while building a testing framework.
If adding non-test items to xunit folder, run app with python -m xunit
.
To add tests, add to tests.py
ensuring to inherit the TestCase and registering the suite with the metaclass. All methods beginning with test
will be run. You can perform setup and teardown by overriding the TestCase default setup()
and teardown()
methods.
# tests.py
class NameForTestSuite(TestCase, metaclass=Suite):
def setup(self):
# optional setup routine
def test_something(self):
...
assert expression
def teardown(self):
# optional teardown routine
All tests in tests.py
can then be run adding the test flag: python -m xunit -t
or --test
.
If cloning, set up a new virtual environment before using:
$ ~/path/to/xunit rm -r -f venv .vscode
$ ~/path/to/xunit python3 -m venv venv
$ ~/path/to/xunit source venv/bin/activate #for POSIX - zsh/bsh
- Invoke test method
- Invoke test setup first
- Invoke tearDown afterward
- Invoke tearDown even if test method fails
- Run multiple tests
- Report collected results
- Log string methods called in WasRun
- Report failed tests
- Catch and report setup errors
- Create TestSuite from a TestCase class