Testing is an essential part of software development, but it is also a divisive subject. There are different opinions on how to approach testing, from test-driven development to code coverage. In this blog post, we will share our thoughts on testing and how to make sure your code continues to work as intended.
When it comes to testing, the first thing that comes to mind is the old saying, “You only need to floss the teeth you want to keep.” In the same way, you only need to test the code you don’t want to break. Tests are there to ensure that your code continues to work, no matter what changes are made to the system.
One common topic when it comes to testing is code coverage. Many people talk about achieving 100% code coverage or maintaining at least 80% coverage. While code coverage is a useful metric to determine if you have tested enough, it doesn’t tell you how well your tests are written or how good your coverage is in terms of behavior. In our experience, code coverage is a metric that can help guide you in identifying what is not covered, but it doesn’t provide a complete picture of your testing.
To properly test your code, you need to consider the behaviors that are added to the system. For example, when adding a new user, you need to test everything that changes as a result of that user being added. This means setting up the state beforehand, executing the behavior, and then verifying the entire state afterwards. It is not enough to simply execute the behavior and check for errors – you need to make sure that the state has changed as expected.
Another aspect of testing that is often overlooked is configuration. As systems become more complex, they often have multiple configurations, and it can be difficult to test all of them. This is where integration tests come in. Integration tests allow you to test how different parts of the system work together, ensuring that the system as a whole continues to work as intended.
In conclusion, testing is an essential part of software development, but it is not just about code coverage or achieving 100% coverage. Testing is about ensuring that your code continues to work as intended, no matter what changes are made to the system. This means considering the behaviors that are added to the system, verifying the entire state after executing a behavior, and using integration tests to ensure that the system works as a whole. By taking these steps, you can ensure that your code is well-tested and continues to work as intended.