Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Testing Windows Service in .Net

I'm developing a windows service in C# .Net and i'm having some dificulty to execute and test my service. I'm using a timer component to run it from time to time and execute my methods. I have to intialize the service all the time to run it. Anyone know a more practical way to test a service?

like image 323
mcamara Avatar asked Feb 21 '11 17:02

mcamara


People also ask

How do I test a Windows Service in Visual Studio?

Start Visual Studio with administrative credentials so you can attach to system processes. (Optional) On the Visual Studio menu bar, choose Tools, Options. In the Options dialog box, choose Debugging, Symbols, select the Microsoft Symbol Servers check box, and then choose the OK button.

How do I debug a .NET service?

Start the service (you can use net start , or start it in the Services window). You should see a dialog box like the following: Select Yes, debug <service name>. In the Just-In-Time Debugger window, select the version of Visual Studio you want to use for debugging.

What is Windows Services in C#?

A Windows service is a long-running application that can be started automatically when your system is started. You can pause your service and resume or even restart it if need be. Once you have created a Windows service, you can install it in your system using the InstallUtil.exe command line utility.


1 Answers

This often boils down to the question what you want to test. Do you want to test the service, or the functionality that it performs? Personally I would...

  • Refactor all of the service functionality into a separate class library
  • Test the library
  • Invoke the library functionality from the service

...and then keep the amount of code in the service itself to the bare minimum needed to trigger the functionality in the class library.

like image 193
Fredrik Mörk Avatar answered Oct 10 '22 08:10

Fredrik Mörk