Testing
Software testing is one of my core skills. Here I talk about testing concepts and testing techniques to create better unit tests.
Posts
You Just Don't Need Tox
Tox is a neat tool for helping test Python projects. It automatically creates “virtual environments” that include the necessary dependencies, and can then run user-defined tools for testing. Multiple environments can be created in a declarative manner to test different combinations of Python versions + dependencies. Tox will also build packages in an isolated environment.
This has been an absolutely fantastic tool in its 15 years of existence. But since then, tooling in the Python ecosystem has moved on, and doing it the Tox way will probably slow you down.
You can get 90% of the value of Tox by wrapping Poetry or uv,
and will end up with simpler, faster, and more flexible QA tooling.
My preferred way to do that is to define tasks with Just,
which enables something quite close to the npm run
style development experience.
Allocator Testing
This post contains a bunch of ideas on testing custom allocators in C, assuming a single-threaded scenario.
Dist::Zilla on Travis CI
With Dist::Zilla (dzil), testing Perl projects on Travis CI can be a bit tricky. Here's my approach.
Should I Separate Unit Tests from Integration Tests?
When does it make sense to keep integration tests separate from your unit tests, and when is it OK to make no distinction?
Well, it's all about getting fast feedback.
Simpler Tests thanks to “Extract Method” Refactoring
I'm currently refactoring a huge method into smaller parts. It is stock full of nested loops, maintains a complex state machine with more variables than I have fingers, and is the kind of code where I have to ask myself how I could ever think this would have been a good idea. So obviously, I'm splitting that function into smaller, independent chunks with the Extract Method refactoring technique.[^1] Since the control flow is now simplified, the code has also become easier to test – as long as I'm comfortable with testing private methods. Why?
The number of test cases needed for full path coverage corresponds directly to the McCabe complexity of the code under test. Since many simple functions often have lower total complexity than one convoluted function, the overall required testing effort is reduced. As this reduction can be substantial, there is a strong incentive to test the extracted methods directly, instead of testing only through the public interface.
Extract Your Dependencies
Making your code ready to be tested
Global dependencies make it difficult to properly test a piece of code. By extracting all dependencies into a single manageable object, we can easily mock the necessary services and avoid a large-scale refactor.