I usually use NUnit as the UnitTest module, but where I work, they use only MSTest. In Nunit, I could use the following:
[FixtureSetup]
public override void MainSetup()
{
_serviceHost = new ServiceHost(typeof(PersonService));
_serviceHost.Open();
}
[FixtureTearDown]
public override void MainTeardown()
{
_serviceHost.Close();
}
I noticed that in MSTest, if you want to initialize throughout the test and close after completing all the tests, you must use the STATIC method below, and as you know, I can no longer use my class. The method is described below:
[ClassInitialize()]
public static void MyClassInitialize(TestContext testContext)
{
_serviceHost = new ServiceHost(typeof(PersonService));
_serviceHost.Open();
}
How can I initialize my Host service once and close after all tests have been run in MSTest?
Thanks for any suggestions.
source
share