Wednesday, 16 January 2008

How to create unit tests for Windows services in Visual Studio 2005

I needed to write couple of unit tests but it also included to write unit tests for Windows service.

First of all I wanted to create NUnit tests but I do not know how to do that and what should I test. Solution for this was use Visual Studion integrated tests. I added Test project to my solution and after that I used wizard for creating new test classes. Visual Studio created skeletons for testing methods and I only implemented what was necesary to check in the test itself. One thing which is quite cool is that VS generated tests also for private methods. This can be accomplished by using reflection.

Other problem was after I implemented tests and wanted to run them. All tests failed. It was because there was no windows service configuration file. It was necessary to copy app.config from other project to the place where is project test dll (name has to be project_test.dll.config). I set project copy app.config everytime the test project is successfully built (as post build event).

No comments: