0% found this document useful (0 votes)
74 views

Test Driven Development

Test Driven Development (TDD) is a software development practice where unit test cases are created before the code is written to test specific functionality. It is an iterative approach combining programming, test creation, and refactoring code. The goal of TDD is to write and fail tests initially, then write just enough code to pass each test, avoiding duplicated code. Tests are run frequently during development to verify code meets requirements at each step.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
74 views

Test Driven Development

Test Driven Development (TDD) is a software development practice where unit test cases are created before the code is written to test specific functionality. It is an iterative approach combining programming, test creation, and refactoring code. The goal of TDD is to write and fail tests initially, then write just enough code to pass each test, avoiding duplicated code. Tests are run frequently during development to verify code meets requirements at each step.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Test Driven Development

(Presented by 4204 Usama bin Abdul


Wahid)

 Test Driven Development (TDD) is a software


development practice that focuses on creating unit test cases
before developing the actual code. It is an iterative approach that
combines programming, the creation of unit tests, and
refactoring.
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).
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.
Tests are written before code and ‘passing’ the tests is the
critical driver of development.
You develop code incrementally, along with a test for that
increment. You don’t move on to the increment until the code
that you have developed passes its test.
Test Driven Development was introduced as part of agile
methods such as Extreme Programming (XP). However, it can
also be used in plan driven development processes.
For Example:
A real-life example: imagine you want to buy a new bike.
First, you check the price online and realize that you do not have
enough money (fail). So you work hard until you got the money,
then go to a shop and buy it (pass).
After some time, you want to buy another bike and try to find a
more efficient way to earn the money needed(refactor).

While writing tests, you should always try to keep them as


small as possible. Small tests help with readability and thus are
easier to understand. Additionally, it is more manageable to track
down errors while debugging in case a test does not pass.

Phases of Test Driven Development


1. Create precise tests: Developers need to create precise
unit tests to verify the functionality of specific features. They
must ensure that the test compiles so that it can execute. In most
cases, the test is bound to fail. This is a meaningful failure as
developers are creating compact tests based on their assumptions
of how the feature will behave.
2. Correcting the Code: Once a test fails, developers need to
make the minimal changes required to correct the code so that it
can run successfully when re-executed.
3. Refactor the Code: Once the test runs successfully, check
for redundancy or any possible code optimizations to enhance
overall performance. Ensure that refactoring does not affect the
external behavior of the program.

What is Refactoring?
Code refactoring is the process of restructuring
existing computer code, changing the factoring—without
changing its external behavior. Refactoring is intended to
improve the design, structure, and/or implementation of
the software (its non-functional attributes), while preserving
its functionality.

Frameworks for Test Driven


Development
Based on unique programming languages, there are multiple
frameworks that support test driven development. Listed below
are a few popular ones.

1. csUnit and NUnit – Both are open source unit testing


frameworks for .NET projects.
2. PyUnit and DocTest: Popular Unit testing framework for
Python.
3. Junit: Widely used unit testing tool for Java
4. TestNG: Another popular Java testing framework. This
framework overcomes the limitations of Junit.
5. Rspec: A testing framework for Ruby projects

Some clarifications about TDD:


TDD approach 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.”

Why we need Test Driven


Development?
 Approach to make the programmer an “Engineer”
 Very lesser bug after development, reduce and rework.
 Software Engineer feel confident about his development.
 Better Documentation.

You might also like