How can I unit test a Windows Service?

前端 未结 7 1685
青春惊慌失措
青春惊慌失措 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:36

    I'd probably recommend designing your app so the "OnStart" and "OnStop" overrides in the Windows Service just call methods on a class library assembly. That way you can automate unit tests against the class library methods, and the design also abstracts your business logic from the implementation of a Windows Service.

    In this scenario, testing the "OnStart" and "OnStop" methods themselves in a Windows Service context would then be an integration test, not something you would automate.

提交回复
热议问题