What is Test-Driven Development (TDD)?

Software TestingAutomation TestingTesting Tools

Test-driven development

Test-driven development, abbreviated as TDD, is a software development technique in which the test cases are defined to specify and prove what the code can do. That is, test cases for each functionality are developed and tested first. If the test fails, then a new code is written to successfully execute the test, and also to make the code simple and defect-free.

The process of TDD begins with designing and creating test cases for every function of the software. The TDD framework helps developers write new code in case the automated test fails. This prevents the code from duplication.

In TDD, we first write and correct the failed test cases, then we write the new code, i.e., before development. This prevents code duplication because a small amount of code is written at a time to pass test cases. Note that, by test cases, we mean requirement conditions that are needed to be tested to fulfil them.

TDD is a process of developing and executing automated tests before the actual development of the software starts. Thus, TDD is also referred to as test-first development.

How TDD test is performed?

Follow the below steps to perform TDD test −

  • Add a test case.

  • Run the tests, and determine if any test fails.

  • Write some new code.

  • Execute the test cases and refactor the code.

  • Repeat the above steps.

TDD is neither about testing nor about designing. In TDD, we do not write some test cases and then build a system that passes the test cases. In TDD, we do not do a lot of testing.

TDD Vs Traditional Testing

TDD is a specification technique. TDD helps ensure that the source code of the software is tested thoroughly at the validating level.

  • In traditional testing, a successfully executed test discovers one or more than one bugs. The same is in TDD. When a test case fails, there is some development or progress as we know that the problem has to be resolved.

  • TDD makes sure that the system meets all the specified requirements. It helps build and boost confidence in the system.

  • TDD emphasizes product code that determines if the testing will be successful or not. While traditional testing focuses on the designing of test cases, and also if the test will execute properly or not to meet the specified requirements.

  • In TDD, complete coverage of the testing is achieved. Unlike traditional testing, in TDD we test each line of the code.

  • TDD and traditional testing, when combines, explain why the testing of the system is so important.

  • In agile modelling, the testing should have a specific purpose. We should be aware of why ae are testing and the level of the testing.

Acceptance TDD and Developer TDD

  • Acceptance TDD − In the case of acceptance TDD, we write a single acceptance test. Acceptance TDD meets all the needs of the specifications and satisfies the specified behaviour of the system. The, we write production or functionality code to meet the acceptance test. Acceptance TDD emphasizes the behaviour of the system. It is also referred to as behavioural driven development.

  • Developer TDD − In developer TDD, developers need to design a single developer test, unit test, and then the production code to fulfil the testing. The unit test emphasizes each functionality of the system. The main objective of developer TDD and acceptance TDD is to define the executable needs of the solution on a just-in-time (JIT) basis, in detail. In JIT, we consider those needs or requirements that are needed in the system to increase efficiency.

Scaling TDD vs Agile Model-driven Development

TDD emphasizes specification and validation. But it does not focus on bigger issues, like design, use of the system, user interface, etc. Agile model-driven development (AMDD) focuses on such agile scaling problems that TDD does not. Therefore, Agile model-driven development is used in bigger problems.

AMDD Lifecycle

In model-driven development, models are created before writing the source code, which eventually has an agile approach.

Envisioning is a TDD(Test Driven Project) process to anticipate the tests to be executed during the preliminary stage of the project. The objective of envisioning is to define the scope and architecture of the system. To make envisioning successful, we perform high-level requirements and architecture modelling.

In envisioning, we do not specify the software in detail, rather we explore the requirements which define the overall strategy of the project.

Iteration 0 − Envisioning

The following are the two main sub-activates of envisioning −

  • Initial requirements envisioning − We might need some days to specify the high-level requirements and to lay out the scope of the system. The aim is to explore the usage of the model, the initial domain model, and the UI model.

  • Initial architecture envisioning − It may take several days to analyse the system architecture. It imparts technical direction to the software. It emphasizes the technology diagrams, UI flow, domain models, and change cases.

Iteration Modelling

In this iteration, we plan the work to be done for each iteration.

  • In general, the agile process is used for such iteration. IN each iteration, new work is added along with its priority.

  • We first consider the work with higher priority. The works added, later on, may be re-prioritized or removed at any time.

  • We discuss how to implement the requirements, for which we use modelling.

  • Modelling analysis and design is performed for all the requirements that are to be implemented for that iteration

Model Storming

It is also referred to as just-in-time modelling.

  • It is done by a team of two-thirds members, and the discussion is done on either paper or whiteboard.

  • One member asks another member to be with them, and each modelling session usually takes 5-10 minutes.

  • The team explores problems until the main cause of the problem is discovered. If one member finds the problem which they wish to resolve, then they take the assistance of other members.

  • Other members explore the problem, and then everyone continues as usual as before. It is also known as stand-up modelling or customer quality assurance (QA) sessions.

Test-driven development Vs Agile-driven development 

Test-driven developmentAgile-driven development
It shrinks the programming feedback loop.It shrinks the modelling feedback loop.
It has detailed specifications.It emphasizes bigger issues.
It emphasizes the development of high-quality code.It emphasizes quality communication with the stakeholders and developers.
It directly communicates with programmers.It communicates with business analysts, stakeholders, and data professionals.
It is oriented non-visually.It is oriented visually.
Its scope is limited to some software works.Its scope is wider than that of TDD and includes stakeholders.

Advantages of TDD

  • Detection of defects at an early stage − In the database world, the testing of code involves manual tests or one-off scripts. With TDD, we can build a suite of automated tests that can be rerun as per our wish.

  • Better design, and cleaner − TDD helps us understand how the code is will be used, and how it interacts with other modules. It gives better decisions on design and provides more maintainable code. TDD also enables writing smaller codes with a single responsibility, which helps us understand the code easily. It forces us to write only production code to pass the test cases as per requirements.

  • Refactor − While refactoring the code, there are risks of breaks in the code. However, with a set of automated tests, such breaks can be fixed. TDD gives faster results, more extensible code with lesser defects in the product that can be updated later on with minimum risks.

  • Teamwork − When a team member is not available for his task, other team members can pick up their work. TDD helps share knowledge, increasing the effectiveness of the team.

  • Developers spend most of the time writing the test cases, however debugging as well as adding new features takes a lot less time. TDD helps developers better analyse the requirements and request clarity from clients. TDD makes developers more productive and helps develop a codebase that is more flexible and easier to maintain.

TDD Frameworks

  • csUnit and NUnit − These open-source frameworks are used in .NET projects.

  • PyUnit and DocTest − These are the most commonly used frameworks for Python.

  • Junit − It is one of the most widely used frameworks for JAVA.

  • TestNG − A popular testing framework for JAVA that overcomes the restrictions of Junit.

  • Rspec − This testing framework is used in Ruby projects.

raja
Published on 30-Nov-2021 07:21:44
Advertisements