RSS Feed

What is Test Driven Development (TDD)?

Test-Driven Development starts with designing and developing tests for every small functionality of an application. In TDD approach, first the test is developed which specifies and validates what the code will do. In normal Testing process, we first generate the code and then test. Tests might fail since tests are developed even before the development. In order to pass the test, the development team has to develop and refactors the code. Refactoring a code means changing some code without affecting its behavior.

The simple concept of TDD is to write and correct the failed tests before writing new code (before development). This helps to avoid duplication of code as we write a small amount of code at a time in order to pass tests. (Tests are nothing but requirement conditions that we need to test to fulfill them).

TDD cycle defines

  1. Write a test
  2. Make it run.
  3. Change code to make it right i.e. Refactor.
  4. Repeat process.

Some clarifications about TDD:

  • TDD is neither about “Testing” nor about “Design”.
  • TDD does not mean “write some of the tests, then build a system that passes the tests.
  • TDD does not mean “do lots of Testing.”

Test-Driven development is a process of developing and running automated test before actual development of the application. Hence, TDD sometimes also called as Test First Development.

How to perform TDD Test

Following steps define how to perform TDD test,

  1. Add a test.
  2. Run all tests and see if any new test fails.
  3. Write some code.
  4. Run tests and Refactor code.
  5. Repeat.

TDD Vs. Traditional Testing

TDD approach is primarily a specification technique. It ensures that your source code is thoroughly tested at confirmatory level.

  • With traditional testing, a successful test finds one or more defects. It is same with TDD. When a test fails, you have made progress because you know that you need to resolve the problem.
  • TDD ensures that your system actually meets requirements defined for it. It helps to build your confidence about your system.
  • In TDD more focus is on production code that verifies whether testing will work properly. In traditional testing, more focus is on test case design. Whether the test will show proper/improper execution of the application in order to fulfill requirements.
  • In TDD, you achieve 100% coverage test. Every single line of code is tested unlike traditional testing.
  • The combination of both traditional testing and TDD leads to the importance of testing the system rather than perfection of the system.
  • In Agile Modeling (AM), you should “test with purpose”. You should know why you are testing something and what level its need to be tested.

What is acceptance TDD and Developer TDD

There are two levels of TDD

  1. Acceptance TDD (ATDD): With ATDD you write a single acceptance test. This test full fill the requirement of the specification or satisfies the behavior of the system. After that write just enough production/functionality code to fulfill that acceptance test. Acceptance test focuses on the overall behavior of the system. ATDD also known as Behavioral Driven Development (BDD).
  2. Developer TDD: With Developer TDD you write single developer test i.e. unit test and then just enough production code to fulfill that test. The unit test focuses on every small functionality of the system. Developer TDD is simply called as TDD.The main goal of ATDD and TDD is to specify detailed, executable requirements for your solution on a just in time (JIT) basis. JIT means taking only those requirements in consideration that are needed in the system. So increase efficiency.

Scaling TDD via Agile Model Driven Development (AMDD)

TDD is very good at detailed specification and validation. It fails at thinking through bigger issues such as overall design, use of the system, or UI. AMDD addresses the Agile scaling issues that TDD does not.  Thus AMDD used for bigger issues.

In Model-driven Development (MDD), extensive models are created before the source code is written. Which in turn have an agile approach.

In above figure, each box represents a development activity.

Envisioning is one of the TDD process of predicting/imagining tests which will be performed during the first week of the project. The main goal of envisioning is to identify the scope of the system and architecture of the system. High-level requirements and architecture modeling is done for successful envisioning.

It is the process where not a detailed specification of software/system is done but exploring the requirements of software/system which defines the overall strategy of the project.

  1. Iteration 0: Envisioning

There are two main sub-activates.

  1. Initial requirements envisioning.It may take several days to identify high-level requirements and scope of the system. The main focus is to explore usage model, Initial domain model, and user interface model (UI).
  2. Initial Architectural envisioning. It also takes several days to identify architecture of the system. It allows to set technical directions of the project. The main focus is to explore technology diagrams, User Interface (UI) flow, domain models, and Change cases.
  1. Iteration modeling: Here team must plan the work that will be done for each iteration.
  • Agile process is used for each iteration, i.e. during each iteration, new work item will be added with priority.
  • First higher prioritized work will be taken into consideration. Work items added may be reprioritized or removed from items stack any time.
  • The team discusses how they are going to implement each requirement. Modeling is used for this purpose.
  • Modeling analysis and design is done for each requirement which is going to implement for that iteration.
  1. Model storming: This is also known as Just in time Modeling.
  • Here modeling session involves a team of 2/3 members who discuss issues on paper or whiteboard.
  • One team member will ask another to model with them. This modeling session will take approximate 5 to 10 minutes. Where team members gather together to share white board/paper.
  • They explore issues until they don’t find the main cause of the problem. Just in time, if one team member identifies the issue which he/she wants to resolve then he/she will take quick help of other team member.
  • Other group member then explores the issue and then everyone continues on as before. It is also called as stand-up modeling or customer QA sessions.
  1. Test Driven Development (TDD).
  • It promotes confirmatory testing of your application code and detailed specification.
  • Both acceptance test (detailed requirements) and developer tests (unit test) are inputs for TDD.
  • TDD makes code simpler and clear. It allows the developer to maintain less documentation.
  1. Reviews.
  • This is optional. It includes code inspections and model reviews.
  • This can be done for each iteration or for the whole project.
  • This is a good option to give feedback for the project.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: