There exists a group of services insInternet 3.5C# and WCF. The NUnit tests require the services to become running and listening for demands. The help need an up-to-date SQL database to be prepared for connection.

Presently the [SetUp] portion of the unit test does two tasks:

  • Execute the most recent SQL scripts to construct the database.
  • Use a System.Diagnostics.Process.Begin to run the commandline mode from the services.

It always works however the services are sensitive for several schema changes, which sometimes fails them. I am searching for the very best practice for setup the database and so the services, as well as ensuring the help are lower in the finish.

The operation is run by MSBuild.

If you are beginning the help, and striking actual performing services...changes are you are not only Unit testing any longer. You are now integration testing.

You need to really consider abstracting your computer data Access into an Interface. After that you can code a concrete implementation of this Interface for normal operation and employ Dependency Injection to inject a mock implementation for the Unit tests.

The very best practice for unit tests are using mock objects which emulate database behavior rather than the actual database.

Excuses have you employed much with Dependency Injection (DI)?

I recommend reading through Jerry Millers blog, she has a whole lot stuff on Unit Testing and DI using .Internet.

Here is a publish to obtain your began on The Dependency Injection Pattern.
Once you have look at this, take a look at his publish on Unit Testing Business Logic.

Using MSBuild is a great start, now its a situation of re invoice discounting the exterior services after which mocking them throughout your test. How complicated you would like the mocking to become can be you.

Here is a SO post on Mocking Frameworks to enable you to get began.

I'd suggest breaking your testing into two separate parts:

  • Unit Testing (where you would employ DI to mock the exterior services)
  • Integration testing (what you're presently doing)

In the finish from the tests you can stop the services you provide utilizing a method using the [TestFixtureTearDown] attribute.