Test Driven Development

 TDD is just about writing the test before the program. In other words, first think about “how to use” any component, why do we need this component or what’s it for?  And only then think “how to implement”. Hence we can say, it’s a testing techniques as well as design techniques.

Below are the advantages of it,

  • It results into components that are easy to test.
  • It results into components that are easy to enhance and adapt.
  • In the end, there is no code without a test.
  • We can tell at any time, whether everything still works as it should, or what exactly does no longer work as it once did.
  • Complex things won’t fear us, execute the test and get positive feedback.
  • You can re-use the unit test in accessing the performance of your system early stage of software lifecycles.

Why test first?

  1. The test is the executable specification.
  • You start thinking about the goal first, then about the possible implementations.
  • You understand the program‘s behaviour by looking at the tests. The tests tell you more than just an API description, they show the dynamics, how to use the API.
  1. You get to the goal as quick as possible.
  2. You don‘t develop unnecessary code.
  3. There is no code without a test.
  4. There is no test without a user requirement.
  5. Once you get one test working, you know it is working now and forever.
  6. You use the tests as regression tests.
  7. The tests give us the courage to refactor.
  8. You can prove that everything still works after the refactoring by simply executing the tests.


What is unit testing and why do we want it?

A Unit Test is a test of a small functional piece of code. Unit Testing makes developer lives easier.

  • Easier to find bugs
  • Easier to maintain
  • Easier to understand
  • Easier to develop


Selecting the Right Framework and Tools

  • Choose the framework such a way that using that you should be able to write test cases meeting the below requirement,
    • Structured
    • Repeatable
    • Cover whole your code
    • Easy to use
    • TDD can be applied to any language and compatible framework should be used. E.g. Junit for Java, nUnit for C# , cppUnit for C++ etc.
  • Integrated development environment
    • For writing tests, using auto-completion and generation of
    • missing code.
    • For running the tests
    • For refactoring
    • g. Eclipse, Visual Studio etc.
  • Build environment
    • For executing tests automatically and during the build process
    • For computing code coverage
    • For generating test reports
    • g. Maven, Gradle etc.


Good Engineering Practices

  1. Having a source code control system
  2. Doing code reviews before checking in code
  3. Checking in code at least daily (even if it leads to build failures)
  4. Having daily builds
  5. Doing unit tests.
  6. Having an automated test harness for unit tests
  7. Using test-driven development at the automated test harness level
  8. Doing continuous builds
  9. Doing acceptance test driven development
    • Apply the acceptance tests once code is checked in
  10. Refactoring


Leave a Reply

Your email address will not be published. Required fields are marked *