Test Driven Development (TDD) - Part One

Today, I am here to talk about what test driven development is and why it’s important along with the related concepts.

Let’s start by putting some questions to understand the concepts.

What Test Driven Development is

  • Development or programming practice that adds the reliability to the Application behavior.
  • Mindset and approach towards software development that enforces writing Unit Tests before/along with coding the functionality.
  • Enforces an interface based design to support loose coupling and modularity.
  • Enforces a check that is done by our code; what we intended?

Why Test Driven Development is important

  • Many projects fail because they lack good testing methodology.
  • Helps the developers by enforcing better design and sense of confidence in terms of quality by regularly checking and looking the test cases execution success. It also helps to avoid break in another dependent area due to any recent changes.
  • Helps Testers by saving their time from logging obvious issues and re-validation, so that they can focus on the complex test scenarios.
  • Helps Project Managers in optimizing the overall budget by having reduced test cycles and less issues at UAT and Production.
  • Helps the client by better overall experience and reduced maintenance cost later.
  • Helps the company in getting repeat business as a result of client satisfaction.
  • Appears natural practice but in reality, it isn’t that common.

Unit Test cases

Unit Test cases are coded to test specific aspects of a functionality. They are created to test positive, negative and exception scenarios. They are independent with other tests in terms of scenario and execution order.

Real-world scenario

TDD is critical especially if the working team is on several modules in tandem and there is a dependency of one module on another.

The image given below depicts why TDD is important when any developer removes the code and realizes later that it broke something else. In this case, if we have TDD, after any change and build, test cases would be examined to make sure that nothing is broken.


Source: Internet

The images given below illustrate how early detection of the issues are important as far as cost is concerned to fix the issues at later stages.


Source: Internet

Now, let’s talk about why, if TDD is so great and awesome, all of us are not using it. Some possible reasons are given below.

  • Not including Unit test cases efforts in an estimation.
  • No experience of TDD in Development Team.
  • Tight deadlines.
  • “Make it work” overrides the quality aspect.
  • No Enforcement of test case creation from Lead/Manager.
  • Client is not asking about test code coverage etc.

Lifecycle of TDD

The images given below depicts the lifecycle; TDD goes through. Typically, it starts with writing negative test cases, then it keeps refining and refactoring the code until it passes.


Unit Test Frameworks

There are several frameworks available, however following are popular.

  • MS Test (Microsoft.VisualStudio.TestTools.UnitTesting)
  • Nunit (Can be downloaded from NuGet)
  • Xunit (Can be downloaded from NuGet)

Conclusion

In this article, i.e. the first part of TDD, we have looked at what Test Driven Development is and why it’s important. In the end, we have also looked at its lifecycle and available Frameworks. In the next part, we will look at how to use TDD with Visual Studio.

I hope you liked the article. I look forward to your comments/suggestions.

Up Next
    Ebook Download
    View all
    Learn
    View all