Welcome to the testing sandbox: practice-driven testing instrument. It can help you to get more comfortable and skilful at writing different types of tests.
The sandbox has five different levels. Here is an approximate plan:
- Basics unit testing (you are here).
- Production-ready unit testing for simple functions.
- Confident unit testing: advanced features, complicated mocking, tests organisation.
- End-to-end tests mastery.
- TDD and PBT.
Some levels can have sub-levels, and every level can have its process of completion.
Level 1 is about the basics of unit testing. It's not enough to be confident at writing tests in production, but it's a solid start of getting to unit testing.
- Read/watch everything in a reading list.
- You have some code in
code.py
. Write tests for this code with 100% branch coverage. - Push tests to your fork of the repo. Make a pull-request to this repo. This is where review will happen. No pull requests will be merged to this repo.
- Ask your colleague to make a review of your code. Fix all errors.
- Ask me (@melevir) to review your code. Fix all errors.
- Hooray!
- Use python 3.9.
- Use latest pytest.
- Don't compose tests in
TestCase
-style classes, use modules instead. - Setup CI/CD with automatic coverage calculation and badge with coverage in readme.
- Before review, make sure, that tests branch coverage is 100%.
- Review considered to be done when reviewer left 3+ comments.
- Use conventional comments.
- If you think, that some somment is not required to fix, use
non-blocking
decorator. - Every comment without
non-blocking
decorator has to be fixed by the author of code.
Read this before writing the first line of code:
- Branch coverage measurement
- Specifying tests (so you don't have to run all the tests each time)
- So, what's a good unit test look like?
Read/watch this during or after writing tests: