Code for Success: Write Tests

David Jones · Jan 27, 2014 · 3 min read · Share:

Writing code that tests code: an essential ingredient to developing an application that lasts. You’d think everyone is doing it, but the fact is they’re not. Rarely does a client approach us with a quality test suite. I’m often surprised if there’s any test suite at all.

Writing tests ensures expectations are met not just once, but for the lifetime of your project. The introduction of regression bugs (new bugs that appear in previously working software) are more likely to occur as your application develops. A test suite can ensure a consistent user experience by minimising this type of bug.

Tests have great benefits for new developers you onboard too.

New developers will be more productive sooner and they won’t jeopardise your project’s integrity.

Put yourself in their shoes. You’re a developer who’s been added to a project for the first time. You look at the code; it’s complex and fairly intimidating. You’ve learned lots but you’re nervous about shipping your first feature. A test suite is your best friend. It can tell you right away if the change you’re making just broke a critical feature. Without a test suite you’re just shooting in the dark.

Not all test suites are created equal. Quality is key.

A quality test suite is hard to quantify but it boils down to three factors: speed, maintainability and coverage.

A fast test suite is ideal. They always start out fast but as you add more features and write more tests they slow down. If they take more than a few minutes to get a result, the process can become painful. You don’t want your developers to be focused on the task of running the tests manually.

Thankfully there’s one tool to help when things get slow. Continuous integration services allow you run your test suite on another computer. They usually run as new code changes are committed. You can be notified as soon as there is a result. This outsources the heavy lifting of running tests and allows your team to focus on writing code instead.

Continuous integration is great for giving visibility to non-technical people.

All stakeholders will be able to see your test suite grow over time and if they’re passing or failing.

As features change in your application so will your test suite so maintenance is essential. You’ll need to add, remove and update tests as requirements change. To reduce the time spent on updating tests, a maintainable test suite is important. This means tests should be easy to read, change or extend. Having tests that are split into smaller logical parts and are not too dependant on each other helps increase their maintainability.

Your test suite is only as good as the amount of features you’re testing. This refers to your test coverage and one way to maximise this is to start with your company's culture. Create a policy where new code won’t be accepted into production without tests. You need to make it clear that your business buys-in on the value of testing. Encourage and nurture your development team by letting them know it’s ok to spend time writing tests. This leads to good test coverage.

Once you’ve setup a testing culture, you’ll find it catches on.

New developers will see this standard and be inspired to match this level of quality — often without being instructed to do so, based solely on the presence of existing tests.

Nurture a testing culture by creating a quality test suite and your business will enjoy the benefits right away, and over the entire life of your application.

Let's work together

Tell us about your project and we'll get back to you shortly.


Join The Conversation

Share and start a conversation about this post: