Write tests – even for your pet projects

« »

I had an interesting discussion recently whereby I asserted that changing the constructor signature of a class should necessarily break some of your tests, if your tests are adequate in their coverage. This tweet generated considerable discussion, and one of the takeaways was a discussion about whether or not writing tests for personal pet projects should be a thing.

I think it absolutely should be.

Writing tests isn’t just about proving whether or not the code works (though this is a key element of why we write tests). Tests also serve as useful, thorough documentation of what you wrote and how it works. Reviewing tests after much time away helps a developer understand exactly what they thought about when they initially developed the code – something that our minds lose the context of over time.

And what about quality? Should a pet project be high quality with tests? Absolutely. Most of us develop pet projects because they do something useful for us. Not writing tests and maintaining a high quality bar cheapens the value of a pet project and ensure you will never know if changes you make in six months will have follow on consequences you can’t see – because your tests don’t inform you.

Writing tests for pet projects also provides valuable practice for writing tests in the professional world. Every test you write makes you just a little bit better at the task. If you reserve test writing for those cases where your professional reputation is on the line, you miss out on those practice opportunities and those unique cases that you might otherwise learn about and apply elsewhere. Not to mention, a project with tests that is a pet project still makes a great portfolio piece for a future employer or client.

To sum up: write tests, even for your pet projects. Testing is a key piece of documenting your software, ensuring its quality, and practicing the art of software development even for projects that no one else might ever see or use. Since writing a test takes a small amount of time but provides tremendous value, there’s no reason to avoid doing it.

Brandon Savage is the author of Mastering Object Oriented PHP and Practical Design Patterns in PHP

Posted on 4/14/2022 at 8:12 am
Categories: PHP, Testing

There are currently no comments.

« »

Copyright © 2024 by Brandon Savage. All rights reserved.