TDD — The practical of Test Driven Development

2o5P...cmGf
2 Jan 2023
81

In this story, I’ll show you how Tests Driven Development works and how I use this approach daily.

TDD is a method to develop software by tests. Basically, the developer writes the test case before writing the implementation.

This approach is essential for software development. I already spoke based on a survey, and with a small part of my experience about how TDD can improve the quality of software, and how it can be helpful for developers to write the software much better.

Check out this story:
https://www.bulbapp.io/p/023f86e3-45d6-497e-a87f-076b1d6f049d/tdd-the-importance-of-the-tests-in-software-development

How does work TDD?

There are many articles about TDD, how does work, and many tutorials on the internet, but I’ll explain how I use this approach in my day by day.


ADD TEST

Before you implement anything, you should create a test scenario, but for a developer to create a test it is necessary to understand the functional requirements to be implemented. This approach makes understanding the use cases easier, and the code design becomes easier to test.



RUN ALL TESTS

Run all tests and see if any failed, it’s necessary to validate if all tests are working correctly and if the new tests did stop the others. The new test that was added should fail because the new functionality wasn’t implemented yet.


WRITE CODE

The next step is to implement the functionality that the result should be the new test that was added to be executed with success. In this scenario, the code doesn’t need to be perfect and clean.


RUN TEST

Run the test which was added that belongs to the implementation in the step “WRITE CODE”


REFACTOR

Now is the best moment, you should refactor the code, and have your code clean. At this point, de programmer can be sure that the refactoring process doesn´t spoil any functionality that exists


RUN ALL TESTS AGAIN

Run all tests again and see if any failed, if all tests are run with success it means that the new functionality, did not stop the others, this brings more confidence for the programmer, and the code has all requirements tested
And …. Repeat All!
You should do this process in little steps.

How to put it into practice?

You can start getting some use cases that you have the knowledge of, trying firstly to write a test use case: For example:

Imagine software that exposes jobs, and you’ll implement a new use case for some jobs in which just candidates older than 18 years can apply for these job opportunities.
So, you could start this implementation by applying a unit test for this case.


Pseudo



Conclusion


TDD is a nice way to you ensure the confidentiality of the software.
With TDD you’ll have software with good coverage of tests. So, you can refactor without feeling fear of the refactors impacts.

Write & Read to Earn with BULB

Learn More

Enjoy this blog? Subscribe to andrelucas

6 Comments

B
No comments yet.
Most relevant comments are displayed, so some may have been filtered out.