Adopting TDD
Testing is so critical that organizations eventually devised a programming style and mindset called TDD. With this approach, we write the test case and run the test on the empty code. The code will fail against the unit testing, and we will start to improve it until it passes the test. This model may seem futile initially, but training a developer’s mind to conceive of code as needing to pass a test has many benefits. For starters, it ensures that software testing is available and valuable right up front. With TDD, we only develop tested features that augment code reliability. SREs can and should adopt TDD for their coding tasks.
But how does TDD work? We can divide this topic into two sections:
- Unit testing the hard way
- Unit testing with a framework
We will first check how to accomplish TDD without using a tool.
Unit testing the hard way
We will use Node.js for this chapter, but you can find plenty of examples in other languages, such...