Test-Driven Development

This is a development approach that changes the way developers test the code of their applications. Previously, developers implemented all the business logic of their applications and once everything was coded, they wrote the tests.

Writing test scripts is not an easy task; just imagine the time it takes to code all the business logic of your application, and the fact that you have to write tests for all the possible scenarios requires a lot of knowledge about the system itself and the level of complexity only increases if you are the sole developer who maintains the code. However, thankfully, there is a better way to test things out. TDD is composed of three simple phases:

Always remember these three colors: red, green, and blue; they represent the TDD cycle. Being in the red phase means that you have written what your piece of code is supposed to do, but the functionality is not implemented yet and the test will fail. Being in the blue phase, it means that you have implemented the code and the test now passes without any problem, but the code might be refactored. Lastly, being in the green phase means that both the code and tests were implemented and passed successfully, and the code is well formatted and easy for any developer to read.

Let's cover each step in further detail to get a close look at TDD phases by coding a simple example.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.224.29.201