Link: PR, Repo
For the task for open source development in this week is adding unit test for Static Site Generator(ssg). There are 3 testing framework options: xUnit, NUnit, and MSTest. I have choose xUnit testing framework for unit testing because xUnit provides good documentation for creating unit test project and unit testing instruction.
Next step is setting up the environment. The first step of setting up environment creates unit testing project and include ssg project. The next step is most hardest part of the task because I have made ssg with static methods which is most testing frameworks do not support. The logic of Static method is assigned to the class itself not a instance of object. Therefore I have to find alternative way to test static methods. I found interesting blog post that I can have unit test with static method! The author, Joydip Kanjilal recommends method called "application – by using wrapper classes and dependency injection" what it is wrap static methods call in instance methods and use dependency injection to inject instance to wrapper class to be tested. Now I can have unit test with static methods with mock framework called moq.
While I was writing the unit testing code, I found some interesting bug. When user choose empty text or markdown file for generating HTML, the application crushes. Therefore I have to handle the error if user input empty text or markdown file. Previous 2 months I have focused on ssg application. The application runs fine and I thought my application is bug free. However, I have found multiple bug during the unit testing. I definitely do unit testing for making better application.