TestingDocs.com
Software Testing website
  • Automation
    • Selenium
    • JBehave Framework
  • Tutorials
    • MySQL Tutorials
    • Testlink
    • Maven
    • Git
  • IDEs
    • IntelliJ IDEA
    • Eclipse
  • Flowcharts
    • Flowgorithm
    • Raptor
  • About

TestNG

Test Driven Development Approach

Introduction

In this post, we will discuss test-driven development approach. First of all, Test Driven Development (TDD) is a development methodology where developers create software by first writing a unit test, then writing the actual code to make the unit test pass. Also, the unit test can be viewed as a specification on how the system should behave. Writing it first, helps the developer to focus on writing code to make the test pass. In simple terms, the developer writes the unit tests prior to the code under test. As a result, the programmer can immediately execute the tests after they are written.

Approach

TDD involves writing automated tests of a software program’s individual units. A unit is the smallest possible testable software component. Developers implement drivers and stubs to support the execution of the unit tests. A driver is a piece of code, which calls other functions. A stub is a prototype skeleton of a method without any code.

Automated testing involves writing unit tests as code and placing this code in a test harness or framework such as JUnit. Automated unit testing frameworks minimize the effort of testing, reducing a large number of tests to a click of a button.

Red-Green-Refactor Cycle:

TDD follows Red, Green, Refactor cycle as shown in the below picture. Red refers to a failing test – the test you write first will not pass because you have not yet written any code for it. Green refers to writing just enough code to make your unit test pass. The Test runner’s UI ( JUnit/ TestNG ) will now show that test passing with a green icon. Refactor refers to refactoring the code so it is tighter, cleaner, and more flexible. This cycle is repeated constantly throughout.

 

Test Driven Development Approach

 

Red

Create a test and make it fail. Create the new code stub. Write just enough code so that it compiles. Run the test. It should fail. This is a meaningful failure, and we expect it to fail.

Green

Make the test pass. Write the code to make the test pass. If the written code makes the test pass as intended, we are done. If new functionality is needed, then another test is needed. Make this one test pass and continue.

Refactor

Change the code to remove duplication in your project and to improve the design while ensuring that all tests still pass. After refactoring, rerun all the tests to ensure that they all pass. Repeat the cycle.

Test-driven development uses the unit tests to design application code. The application is better designed and maintained easily. The application developer gains confidence that the software is working, by running the tests.

 

TestNG Tutorials on this website can be found at:

https://www.testingdocs.com/testng-framework-tutorial/

For more details on the TestNG Framework, visit the official website of TestNG at:

https://testng.org

Related Posts

Tests TestNG Suite testng.xml

TestNG /

Run tests from TestNG Suite testng.xml file

Add TestNG library

TestNG /

Add the TestNG library to the project

new TestNG class

TestNG /

Create TestNG test class in Eclipse IDE.

TestNG Plugin IntelliJ

TestNG /

Enable TestNG in IntelliJ IDE

Installing Eclipse from Update Site

TestNG /

Install TestNG latest version from the update site

‹ TestNG Annotations› TestNG @Test Annotation Attributes

Recent Posts

  • MS Access Data Types
  • Install RAPTOR Avalonia on CentOS
  • Download RAPTOR Avalonia Edition on Windows
  • npm doctor command
  • Build & Run CLion Project
  • Create New CLion C Project on Windows
  • Configure CLion Toolchains on Windows
  • Launch CLion IDE on Windows
  • Activate CLion IDE
  • CLion IDE for C/C++ Development

Back to Top

Links

  • Contact
  • Privacy Policy
  • Cookie Policy

www.TestingDocs.com

Go to mobile version