Test Driven Development Methodology (TDD)

Overview:

TDD is one of the core practices of Extreme Programming (XP). TDD represents a simple evolution in the way software can be developed. It is the realization that complex software systems can be developed in small simple increments that use tests to drive the design and implementation of the software.

TDD is a very simple methodology that relies on two main concepts: unit tests and refactoring.

TDD is basically composed of the following steps:


Step 1:
Write a test that defines how you think a small part of the software should behave

Step 2:
Make the test run as easily and quickly as you can. Don't be concerned about the design of code, just get it to work.

Step 3:
Clean up the code. Now that the code is working correctly, take a step back and refactor to remove any duplication or any other problems that were introduced to get the test to run.

TDD is an iterative process, and you repeat these steps a number of times until you are satisfied with the new code.

Tools Selection:

Various technology and sdk support this unit test development via standard unit test frameworks, for example

Java : JUnit. This is a Unit test framework for the java programming language
Reference: junit.org

DotNet: NUnit. This is a unit test framework for the dot net programming language such VB.net and C#.
Reference: nunit.org


Object Mackup or Layer Mackup: when we do unit testing we use to test the small unit of code. But this code might interlinked multiple layers. To Mock those layers (DAO, Model, Delegator, VO, BO, Helpers etc), we use the framework called EasyMock or MockIt Java development framework. This record and playback API provide the flexibility to write and test the effective unit test cases.
Reference: easymock.org
Reference: npmjs.com

For java projects, developer can use any Java based IDE such as Eclipse, JDeveloper, RSA/RAD etc and configure the above plugins and links those into Project reference.

Use Ant as Build script sdk to compile, build and deploy the java binaries. Ant build script to be configured based on the structure of your project with multiple targets.
Reference: ant.apache.org


For Example Let's take the Java Development,

Step 1: Open the Eclipse IDE, create an Java development Project and Named as "TDDHelloWorld"

Step 2: Create two source folders under Main ( sr c, Test)

Step 3: Create the package under sr c, called " com.gets.tdd.helloworld"

Step 4: Create the package under test called " test.gets.tdd.helloworld"

Step 5: Create the Java Interfaces and Implementation Concreate Java class under "com.gets.tdd.helloworld.HelloWorldImpl.java" and define method signature with inputs and outputs.

Step 6: Create the Junit test cases as per junit construct and implement the junit concreate class under "test.gets.tdd.helloworld. HelloWorldImplTest.java

Step 7: Unit test cases should cover (Min and Max) Boundary condition, Happy path, Negative path, Null Pointer Exception and Runtime Exception coverage.

Step 8: Run the Test case, first time all the test cases will fail (RED).

Step 9: Implement the Concrete Impl class with appropriate functional logic and ensure the code is working till all the test cases are pass (GREEN)

Step 10: create java test suite and link the list of test classes.

Step 11: create the build script which will invoke the Junit target after the compile the java classes.

Benefit of TDD:
- Simple and incremental development
- Simpler development process
- Constant Regression Testing
- Improved Software design and code quality

About Author / Additional Info: