Test Driven Development
Test Driven Software Development is our philosophy and for us the most important quality factor we can rely and improve on. By having a reliable test suite you:
- Have a living documentation of your software
- Knowledge around implementation is readable and executable
- Have tests to stop bugs reappear in production
- You can automate on it a lot of additional things like updates of third-party components
We Write Tests First
A very important point is to write tests first, to cover the thoughts and cases a developer is thinking about while trying to solve them in software. What you get on this approach for free:
- All possible (mostly relevant) cases covered by unit tests, which guarantee to work
- If your write tests first, you see them failing. Nobody needs tests, which pass where they should fail.
- By covering the thoughts and findings the developer frees his/her mind for the next task
- He/She may handover the code to another developer guaranteeing he/she has done the best possible work
- Replacing/Improving (also called refactoring) code is a pleasure, as the tests will show you, what you have missed or broken.
If a developer doesn’t write tests first, she/he may:
- miss a case he was thinking about while coding (there may be a lot)
- or forget about it (due to disturbance or lost focus)
- the current implementation may solve a case, the next developer touching the code will not think about it
- The code may become dependable on the developer/person who has written it
Bugs are Missed Cases or even Opportunities
If you have written software yourself, you may know how complex a task may get. Every bigger (and even small) software have and will have bugs. We can’t stop bugs, but we can write tests, which will stop bugs to reappear over and over again.
Writing tests for a found bug and fixing it afterward guarantee, that the tests cover the bug and the fix is working.
Tests are an Executable Documentation
Writing documentation is for most developers, not their primary and beloved job, that’s why it is hard to keep it up to date. Still, documentation is an important part of the project, but the details and single cases are better matched by tests. They are mostly covered by unit tests. If the software changes, the tests must be aligned to match the changed implementation. These way they stay up to date with the project.
Writing user stories is an important part, to show developers, what they should do and how the software should be used. A developer should write integration tests to cover the user stories through tests, which use the software through an interface (like a browser) a user would normally use.
Every Software will change
Most applications change over their life cycle and for bigger software systems they are whole teams, to cover this work. But why software changes without changing a single line of code it was written for:
- The platform the software was written for, may change (from x86 to AMD64, AMD64 to ARM).
- Operating systems get updates or become unsupported
- Programming languages evolve
- Security and regular updates on third-party components
As the world around us doesn’t stop moving, we must handle changes around business and parts our software relies on.
Tests help with updates
A bulletproofed test suite will help you run updates and guarantee working software on most changes. The developer will see breaking changes and can refactor the code to fix them.
You can run updates upfront and tests the changes through your test suite. It helps handle breaking changes at the right time. Tests are an essential part of updates automation.
Test Suite Automation
A well-written test suite can do even more:
- Make changes and run the corresponding tests immediately to see, whether they are passing or something fails (breaks).
- With a reliable test suite you can run most security updates on third-party components (almost) automatically
- Automation of Updates on third-party components by your Continuous Integration (CI) System. Your CI tries to update the component and run your tests suite to see, whether something is broken after the update. You can safely merge the update at any time and be sure, it is fine.
- The tests are run at least twice as often through using a CI
- The tests can even be run after every commit (change)
Test in numbers
The test suite can be analyzed and show things like:
- Test coverage (on code and in percent of the whole project)
- Find code that is not covered by a test
- See what is covered by which test
- See which code is covered by unit tests
- Which code is covered by integration tests
As most of these things are a help for software development, it shows the management, how carefully the work is done, and where there is potential for improvement.
Test Driven Development is an essential part of modern software development, as it helps to create reliable and future-proof software. Automation around software tests using Continuous Integration and Continuous Delivery boosts development and provides a safety net for companies as they rely on it.