Test driven development

Coding scenario without TDD.

First let us see an example scenario where we have a developer Jim coding something without using TDD.

  • Jim starts working on a feature
  • He reads the specs and gets the big picture on what has to be done.
  • He sees that he as a new Screen to create where he will fetch some data from the database, do some business processing and then display it on the screen.
  • He starts to code the UI screen.
  • Then he code the functions to fetch from the database and do the business processing.
  • He then boots the application to test his feature.
  • Shit happens, he is getting an exception pop-up on the UI.
  • He debugs the issue and then re boots the application to test.
  • Exception pop-up no longer appears but the data displayed is wrong and he has no idea why.
  • He asks his senior Sam for help.
  • What do you think Sam will do?

What is test driven development?

  • TDD is a design tool, enabling us to drive our implementation with the help of tests.
  • The point of TDD is that it forces you to have a direction in mind before you start charging into the fray, and having a direction in mind leads to better designs.
  • TDD relies on the repetition of a very short development cycle.

TDD workflow.

  • The developer writes an initially failing automated test case that defines a desired improvement or new function.
  • He produces the minimum amount of code to pass that test.
  • Finally he refactors the new code to acceptable standards.

Advantages of TDD

  • Quality of the Code
  • Find bugs early
  • Provides in code documentation
  • Debugging
  • Design
  • Confident changes and Integration
  • Reduces cost

Behaviour driven development

Behavior Driven Development (BDD) is a branch of Test Driven Development (TDD). BDD uses human-readable descriptions of software user requirements as the basis for software tests.

What’s the Difference Between TDD and BDD?

In TDD (Test Driven Development), the test is written to check the implementation of functionality, but as the code evolves, tests can give false results. BDD (Behavior Driven Development) is also a test-first approach, but differs by testing the actual behavior of the system from the end users perspective.

BDD workflow

References

Leave a Reply