Tested and working!
How (and why) I implemented tests in RedeeMOD
The reason behind “why”
My dad is a high profile developer, and many new things I try are influenced by him. While I always liked setting up CI/CD pipelines and other automations, one thing my projects lacked was testing.
Turns out, many tech jobs require knowledge about tests, because they guarantee several things:
- They assure that your application works as it should
- They document your working concept
- They let you make refactors that don’t hurt the functionality
So, after considering these benefits, I started reading how tests are implemented.
How did I implement tests for RedeeMOD?
There are 3 main types of tests:
- Unit (where one small component is tested)
- Integration (where several combined components and their behaviour is tested)
- End to End (where full system flow from start to finish is tested) (they take a long time, so I didn’t even consider them for RedeeMOD)
First thing any testable software should have is clear dependency injection.
Dependency injection is a pattern where you don’t call dependencies directly, but pass them externally. I opted for implementing method argument injection that I could later use in tests.
Why is DI required? Well, during testing, the external environments must be mocked and created virtually to test different use cases (things like sys.* calls and more). Luckily, RedeeMOD already had a nice and semi-testable architecture where very few things needed to be changed.
Writing tests is a tedious and rather boring process, because all the edge cases must be defined. Don’t hate me for this, but I handed over writing tests to AI. My arguments for why AI is appropriate for this are:
- You can’t test software that hasn’t been previously written (by people)
- Repetitive work takes away precious time, and AI just performs checks
While one could argue that Test-Driven Development exists, after trying it out I can confidently say that I’m not a fan of TDD.
However, giving very broad instructions, like “Make me tests for this project” usually doesn’t go well, because AI can’t retain project philosophy and tests what doesn’t need to be tested (things that don’t contain logic, thus can’t really fail).
RedeeMOD currently has a test suite based on pytest with integration and unit tests written.
How tests could benefit you?
With tests, instead of clicking around (and often forgetting) every edge case manually, you can offload it to a machine that does hundreds of calculations extremely fast. Not only is it a well-regarded pattern within the developer community, but also helps with coding efficiency and guards from failed refactors.
Comments 0
No comments yet. Be the first!
Sign in to join the conversation.