How can I unit test a Windows Service?

前端 未结 7 1691
青春惊慌失措
青春惊慌失措 2020-12-08 13:03

.NET Framework: 2.0 Preferred Language: C#

I am new to TDD (Test Driven Development).

First of all, is it even possible to unit test Windows Service?

7条回答
  •  心在旅途
    2020-12-08 13:23

    I have unit tested windows services by not testing the service directly, but rather testing what the service does.

    Typically I create one assembly for the service and another for what the service does. Then I write unit tests against the second assembly.

    The nice thing about this approach is that your service is very thin. Basically all it does is call methods to do the right work at the right time. Your other assembly contains all the meat of the work your service intends to do. This makes it very easy to test and easy to reuse or modify as needed.

提交回复
热议问题