More

    INTRODUCTION TO TEST DRIVEN DEVELOPMENT (TDD)

    Test Driven Development (TDD) also called as test-first approach by many, is a development approach where we first write tests based on our requirements before writing actual production code.

    TDD makes sure that all the intended features of the program are working as expected. Kent Beck, who is credited with having developed or “rediscovered” the technique, stated in 2003 that TDD encourages simple designs and inspires confidence. (source = Wikipedia)

    A Test-Driven Development (TDD) cycle usually may have following steps:

    1. Write a test
      1. Each new feature begins with writing a test that defines a function or improvements of a function. It makes the developer focus on the requirements before writing the code.
    2. Run all tests and see if the new test fails
      1. This validates that the test harness is working correctly.
      2. Shows that the required behaviour did not already exist.
      3. Rules out the possibility that the new test is flawed and will always pass.
      4. The new test should fail for the expected reason.
    3. Write the actual code
      1. Write code that causes the test to pass. The new code written at this stage is not perfect and may, for example, pass the test in an inelegant way. That is acceptable because it will be improved and honed later.
    4. Run tests
      1. If all test cases now pass, the programmer can be confident that the new code meets the test requirements, and does not break or degrade any existing features. If they do not, the new code must be adjusted until they do.
    5. Refactor code
      1. The growing code base must be cleaned up regularly during TDD.
      2. New code can be moved from where it was convenient for passing a test to where it more logically belongs.
      3. Duplication must be removed. It also applies to the removal of any duplication introduced to pass the test in previous steps.
      4. Object, class, module, variable and method names should clearly represent their current purpose and use, as extra functionality is added.
      5. By continually re-running the test cases throughout each refactoring phase, we can be confident that process is not altering any existing functionality.
    6. Repeat
      1. Starting with another new test, the cycle is then repeated to push forward the functionality. The size of the steps should always be small.

    TAGS: testing

    REFERENCES:

    Recent Articles

    OAUTH – FREQUENTLY ASKED QUESTIONS FOR INTERVIEWS AND SELF EVALUATION

    Why is refresh token needed when you have access token? Access tokens are usually short-lived and refresh tokens are...

    SUMO LOGIC VIDEOS AND TUTORIALS

    Sumo Logic Basics - Part 1 of 2 (link is external) (Sep 29, 2016)Sumo Logic Basics - Part 2 of 2...

    GIT – USEFUL COMMANDS

    Discard all local changes, but save them for possible re-use later:  git stash Discarding local changes...

    DISTRIBUTED COMPUTING – RECORDED LECTURES (BITS)

    Module 1 - INTRODUCTION Recorded Lecture - 1.1 Introduction Part I – Definition

    BOOK REVIEW GUIDELINES FOR COOKBOOKS

    Whenever you add reviews for the book, please follow below rules. Write issues in an excel.Create an excel...

    Related Stories

    Leave A Reply

    Please enter your comment!
    Please enter your name here

    Stay on op - Ge the daily news in your inbox