2

I have here a Windos Service Project in Visual Studio and because you cannot start a service without installing it, I have to compile + uninstall old service + install new service again and again if I want to test some changes on my code. This is taking forever.

Is there no easier way to test windows services? Thank you

silla
  • 1,257
  • 4
  • 15
  • 32

2 Answers2

2

Run the service from VS as a console application. In fact, if you are smart, you can test whether

Environment.UserInteractive

This way with a simple "if" you can have your service running normally, without the windows service stuff if you run it in an interactive mode or, if it is run as a service, you perform a normal service startup.

Wiktor Zychla
  • 47,367
  • 6
  • 74
  • 106
1

When testing services, I would usually recommend to separate the functionality from the hosting. And test the functionality in an independent manner.

What this means is the your probably spawns a worker thread in OnStart, and this thread instantiates and calls some class methods that represent the actual workings of the service. Technically, this piece of logic should not explicitly care where it runs, console app, windows service or a web service etc..

I I would advise you to test this logic directly, for example in unit tests, where the logic is hosted by visual studio itself. This is not to suggest you should not test the service, but this can be done manually or automatically, especially during QA or Sanity testing, where it is OK to run tests that take a long time to execute.

Vitaliy
  • 8,044
  • 7
  • 38
  • 66