I usually use NUnit as a UnitTest Framework ,however where I work now they use solely MSTest . In Nunit I could use the following:
[FixtureSetup]
public override void MainSetup()
{
开发者_JAVA百科 _serviceHost = new ServiceHost(typeof(PersonService));
_serviceHost.Open();
}
[FixtureTearDown]
public override void MainTeardown()
{
_serviceHost.Close();
}
I have noticed that in MSTest if you want to initialize for the duration of all test and close after all tests have run you have to use below STATIC method and as you know I cannot use my class anymore. The below method will crash!!!
[ClassInitialize()]
public static void MyClassInitialize(TestContext testContext)
{
_serviceHost = new ServiceHost(typeof(PersonService));
_serviceHost.Open();
}
How can I initialize my service Host once and close after all the test have run in MSTest?
Thanks for any suggestions
If you make the _serviceHost
variable static too, you should be safe.
精彩评论