“Test first, test first!” (TDD)
By: Figo Muhammad
Tags: Agile, Guides And Tutorials, Tdd, Software Development, Testing

Green

This next phase is the development phase. The goal of this phase is to make all the tests pass. Developers should minimize writing a code that does not contribute to making the tests pass. They must be focused, no derailing into other less prioritized work. They should only write sufficient code.

Developers move to the next phase if all the tests made in the Red phase have passed. If some tests fail, they have to stay in this phase.

Example in my project — all the green commit tests have passed.

Refactor

By Xarawn — Own work, CC BY-SA 4.0, https://commons.wikimedia.org/w/index.php?curid=44782343

This phase is all about cleaning the code. Developers clean the code to make it easily understandable, adaptive to change, and also more time and space-efficient. In this phase, developers must frequently run the tests after refactoring to check the integrity of the code and they have to fix the code or tests until all tests are passed.

I made an article on how to clean codes in the link below.

Additional Workflow

In my team’s workflow, we add a tag at the beginning every commit message in Git:

“[Red]” in every “Red” commits, “[Green]” in every “Green” commits, and “[Refactor]” in every “Refactor” commits.

This helps us to identify in what phase is each commit. Therefore, we can easily roll back to a certain commit if there is a problem.

Frontend vs. Backend Testing

What to test is different for the backend and frontend application. Frontend testing focuses more on the user interface (UI) or the presentation layer, e.g. ReactJS. It tests the existence of the UI and its functionality (the event handlers). For example, it tests whether a page has correct components and also tests the functionality of an input field, a button, an image, etc. The tests are often the direct translation of the mockup. Hence, the tester must know the business logic of the application in order to make the tests. Frontend testing does not deal with the database nor use the SQL queries.

Backend testing performs in the application, e.g. Django, and the database layer, e.g. PostgreSQL. It uses the data stored in the database while performing the test. Backend testing is important to check data loss, data corruption, deadlock, etc. Sometimes, the backend testing also has to deal with business logic that is located in the application layer. Backend testing does not deal with the UI as the frontend testing does. Therefore, the tester must have the knowledge of databases and some algorithms for the business logic in the application layer.

Summary

Test-driven development or TDD is a reversed development process that can benefit developers in the long run. It has three phases:

Red — make failing tests from the software requirement, Green — develop the code to pass all the tests, and Refactor —make the written code more readable, understandable, and more efficient.

I think that is all from me. Any suggestions or comments are highly appreciated. They help this article to be more helpful to others, so please let me know. Thank you!

References

Percival, Harry. Test-Driven Development with Python, O’Reilly, June 2014.