Working with Test Driven Development

A technique for using automated unit test scenarios to design and decoupling of dependencies is called Test Driven Development. This technique is heavily used in Agile development methodologies. To use this technique with Visual Studio Team System, you have to understand the following topics:

  • Creating and running automated tests inside the VSTS IDE
  • Abstracting dependencies in an object-oriented world
  • Re-factoring new and old features to remove duplication in the code

The main theme of TDD is “Red, Green, Refactor.”

  • To work with TDD you must have a Test Project solution for creating new test cases in VSTS and it should reference the class library where you are adding new functionality.

Test Development

Follow these steps to perform TDD:

  1. Understand the requirements of the user story and feature that you are working on.
  2. Red: Create a test and make it fail.
    1. Write the test for already existed code and change the logic of the code to make our test fail.
    2. Run the test case. It should fail. This means your test is calling the correct code and that the code is not working by properly. This is a meaningful failure, and you expect it to fail.
  3. Green: Make the test pass
    1. Initially hard code the expected return value to verify success after that write the correct logic of code to make the test pass.
    2. If you’ve written the code so that the test passes as intended, you are finished. You do not have to write more code speculatively. If new functionality is still needed, then another test is needed. Make this one test pass and continue.
    3. When the test passes, you might want to run all tests up to this point to build confidence that everything else is still working.
  4. Refactor: Change the code to remove duplication in your project and to improve the design while ensuring that all tests still pass.
    1. Remove duplication caused by the addition of the new functionality
    2. Make design changes to improve the overall solution.
    3. After each refactoring, rerun all the tests to ensure that they all still pass.

Advantages of Test-Driven Development

  • When the unit test case passes success and logic of the code is refactored to remove duplicate code.
  • The unit tests will not expire until you separate documentation and this will feedback that each component is still working.
  • TDD will help the Developer to understand the complete design and critical analysis of requirements to work with the logic of code and get an accurate result.
  • Any software developed using TDD can be maintained easily, better designed.
  • If a bug is found, the developer should create a test to reveal the bug and then modify the logic of the code until successive test run, all old bugs is verified and Reduced debugging time.

Limitations

  • Due to extensive use of test cases, all code logic is not executed success or failure properly.
  • Some Security Issues for Integration testing and Compliance testing

Read about Behavior Driven Development here.

Trigent’s experienced and versatile Quality Assurance and Testing team is a major contributor to the successful launch, upgrade, and maintenance of quality software used by millions around the globe. Our experienced responsible testing practices put process before convenience to delight stakeholders with an impressive industry rivaled Defect Escape Ratio or DER of 0.2.

Author

  • Mallesh Vibhuti

    Mallesh Vibhuti is a Senior Software Engineer with Trigent Software. With over six years experience he is skilled in languages such as C#, WinForms, SQL Server, MySQL, SSRS, ADO .NET and WCF. Mallesh enjoys adapting to new technologies really quickly.