Posts

Showing posts from July, 2019

Adding unit tests to legacy code

With the release of MS one version of D365FO automatic testing is becoming more important. These are some methods and tips on how to add a test harness to your legacy code. 1. Identify change points Start by looking at the class you want to add a test harness to, consider what needs to change in order to implement unit tests on it. 2. Find test points Test the public methods, not private methods. This way it's easy to make changes to the internal workings of the class in the future without affected what other classes depend on. 3. Break dependencies Add interfaces to the classes that the class you are work on depends on. Modify the class you are working on so that it depends on the interfaces that the dependencies implement instead of the classes and add the possibility to inject dependencies. For example by allowing injection of dependencies on the class creation. 4. Write tests Implement tests on the class, make sure they pass. 5. Make changes and refactor Make