Test Driven Development

Many software engineers will tell you a feature, an application or even a device that has not gone through rigorous testing has far-reaching implications. This brilliant article published by Eric Elliot attributes failure to do TDD thoroughly as one of the causes of the Boeing 737 Max crashes( Must read btw). Its like when we go to the hospital for treatment, doctors carry out tests before prescribing drugs for us to take making sure they are doing the right thing.

In this article I will try to explain what TDD is , its advantages and disadvantages, the TDD cycle, what constitutes a good test? and lastly the types of tests. Enjoy…..

So what is Test Driven Development? Test driven development is the process of writing tests for your production code before you actually write the production code. That function supposed to perform a certain task in your application must be tested to ensure its maintainable and robust.

Advantages of TDD

  • Developers are known for their problem solving skills so TDD comes in to help in the thought process.
  • TDD helps to improve communication among the development team.
  • TDD improves the structure of our production code.
  • Developers wont be worried to make changes to their code for fear of code breaks.

Disadvantages of TDD

  • TDD takes a long time than just writing code without tests.
  • There is a likelihood of writing bad tests.

Then we have the TDD cycle called Red, Green, Refactor, a framework used by developers to do the following;

  • Red -Write a failing test.
  • Green -Write production code that is just enough to make the test pass.
  • Refactor -And lastly, refactor the code you wrote.

How does one tell they have written a good test? “TDD the RITE Way” by Eric Elliot explains how one should approach writing a good test. Lets try and go though them together;

  1. Readable
  • Our tests should properly define our code so that developers on your team don’t have a hard time understanding its true intentions.

2. Isolated

  • Tests should be separate to avoid affecting each other negatively.

3. Thorough

  • Remember when I mentioned how tests should be rigorous enough? Your tests should satisfy all possible scenarios.

4. Explicit

  • Details or information to reproduce our tests should be available for anyone accessing our tests. Just like a readme file in our GitHub repo that explains what your project is about, the packages to install, etc.

Types of tests

The three main types of tests include;

  1. Unit tests
  • Test individual pieces of functionality making sure each unit of the software code performs as expected.

2. Integration tests

  • Make sure the individual pieces of our code work together for instance the client, API and server are communicating seamlessly.

3. E2E tests

  • The user wants application to work as expected, doesn’t care about the nitty gritty. For instance, when I press the button to add an item to a cart on an ecommerce site I expect to see the item selected.

Conclusion

We have gone through the following;

  • What TDD is ?
  • advantages and disadvantages of TDD.
  • The TDD cycle.
  • And lastly, the three main types of tests.

Next steps

We shall get our hands dirty in the next series by writing unit tests. Stay tuned… 😊

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store