The growth of Agile development has proposed many pragmatic practices for delivering quality software at high speed. Test-Driven Development (TDD) is one such practice that is now classical as an accomplished process that drives positive results.
Test Driven Development (TDD) is a software development process that focuses on creating unit test cases before developing the actual code. It is an iterative process that altogether connects programming, the creation of unit tests, and refactoring.
TDD is an iterative development process. In TDD, developers write enough tests before they write production code to
write a test before they write just enough production code to satisfy that test and the subsequent refactoring. Developers use the specifications and they will first write a test describing how the code actually should behave.
How to perform TDD Test?
The following steps define how to perform the TDD test,
1. Add a test.
2. Run all tests and check the result and if there is any failure
3. Write some code.
4. Run tests and Refactor code.
5. Repeat.
TDD cycle defines
1. Write a test
2. Make it run.
3. if fails then make changes i.e., Refactor.
4. Repeat process
What is acceptance TDD and Developer TDD:
With Acceptance TDD you write a single acceptance test. here the test will fulfill the requirement of the specification. After that write just adequate production/functionality code to accomplish that acceptance test. The acceptance test will mainly focus on the overall behavior of the system. Acceptance Test Driven Development also known as Behavioral Driven Development (BDD).
With Developer TDD we write a single developer test which can be known as a unit test and then just enough production code to fulfill that test. The unit test will cover each and every functionality of the system. Developer TDD is simply known as TDD. The main objective of ATDD and TDD is to specify detailed, executable requirements for your solution on a JIT (just in time) basis.
Here in this Test Driven Development example, we will define a class Username. For this class, we will try to satisfy the following conditions.
A condition for Username acceptance:
First, in this Test Driven Development example, we write the code that fulfills all the above-specified requirements.
Scenario 1: To run the test, we create class UserName();
We
will run above class UserNameTest ;
Output
is PASSED as shown below;
Scenario 2 : Here we can see in method UserNameTest() there is no need of creating an object of class username.so we remove that.
We will remove UserName userName=new UserName() from UserName class ; We can call the isValid () method directly by UserName. IsValid (“Deepali”).
But we are unable to do it because we cannot call a non-static method without creating an object of the class. To call this method we have to Refactor the code as below:
Here we have added a static keyword before a method name then call the UserNameTest class and check the result.
But we are unable to do it because we cannot call a non-static method without creating an object of the class. To call this method we have to Refactor the code as below:
Here we have added a static keyword before a method name then call the UserNameTest class and check the result.
below we can check the result after refactoring the code:
After making changes to class UseName() if we run the test then the output will be PASSED as shown above
Deepali works as a Software Development Engineer in Test, at QACraft, she is a computer science engineer with a degree of bachelor and has 3+Years of experience in the software industry as a Manual Tester and Automation Test Engineer. In her free time, she loves reading and podcasts.
© Copyright 2024 QACraft Pvt. Ltd. All rights reserved.
Contact : +91 9157786796
Error: Contact form not found.
deepali