Microsoft Dynamics NAV - C/SIDE Solution Development -

Microsoft Dynamics NAV – C/SIDE Solution Development

Locus IT ServicesMicrosoft Dynamics NAV – C/SIDE Solution Development

Lesson 1: Test-driven Development Fundamentals

Test-driven Development Fundamentals

Test-driven development  Fundamentals (TDD) is an advanced technique that uses automated unit tests to drive the design of software and force decoupling of dependencies. The technique results in a comprehensive suite of unit tests that you run at any time to provide feedback that the software is still working. Developers who use the agile development methodology favor this technique. The motto of test-driven development is “Red, Green, Refactor.”

  • Red: Create a test and make it fail.
  • Green: Make the test pass by any means necessary.
  • Refactor: Change the code to remove duplications in your project and to improve the design while making sure that all tests still pass.

These steps explain the example TDD process:

  1. Understand the requirements of the story, work item, or feature that you are working on.
  2. Red: Create a test and make it fail.
    1. Imagine how the new code should be called and write the test as if the code already existed.
    2. Create the new production code stub. Write just enough code so that it compiles.
    3. Run the test. It should fail. This is a calibration measure to make sure that your test is calling the correct code and that the code is not working by accident. This is a meaningful failure, and you expect it to fail.
  3. Green: Make the test pass by any means necessary
    1. Write the production code to make the test pass. Keep it simple in Microsoft Dynamics NAV.
    2. Some developers advocate hard-coding of the expected return value first to verify that the test correctly detects success. This varies from practitioner to practitioner.
    3. If you have written the code so that the test passes as intended, you are finished. You do not have to write more code. If new functionality is still needed, then another test is needed. Make this one test pass, and then continue.
    4. When the test passes, you might want to run all tests to this point to guarantee 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 that is 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 make sure that they all still pass.
    4. Repeat the cycle. Each cycle should be very short, and a typical hour should contain many Red/Green/Refactor cycles.
Locus IT Project Management Office
What’s it?