Testing Guidelines

This testing guide is based on pytest.

Main principles

Tests must start with a clean state

This means prefer beforeEach to before. Re-instantiate objects before running each it blocks. Create every file required by a test in a beforeEach (or commit them in fixtures/). Reset any side effects done on the test environment after each test.

Tests must be runnable in isolation

Each test must pass if they’re run alone. You can run a single test by using TODO.

Stub most performance heavy operation

TODO

Naming convention

Tests far module.py are contained in a test_module.py file. We prefer simple functional style over class style organization of tests. BE CLEAR ABOUT THE INTENT OF THE TEST. Express what you want to test in the name. If it needs more explaining then add comments.

Assertion

Don’t add message to assertions unless the error thrown makes it unclear what failed.

If you must add a message, then describe the expected outcome and why it failed. For example:

// BAD
assert generator.appname, 'Generator has an `appname` property'

// GOOD
assert generator.appname, 'Expected Generator to have an `appname` property'

Remember that these message are the error message thrown with the failure. Let those be useful in these occasions.

Style Guide

Be explicit

Always be explicit about what it is you want to test.

Test own code

If you start testing 3rd party functionality stop. Maybe it is time to refactor the code and make it more testable or use mocking, stubbing etc.