【发布时间】:2011-12-06 20:52:16
【问题描述】:
我通常使用 NUnit 作为 UnitTest 框架,但是我现在工作的地方他们只使用 MSTest。 在 Nunit 中,我可以使用以下内容:
[FixtureSetup]
public override void MainSetup()
{
_serviceHost = new ServiceHost(typeof(PersonService));
_serviceHost.Open();
}
[FixtureTearDown]
public override void MainTeardown()
{
_serviceHost.Close();
}
我注意到,在 MSTest 中,如果您想在所有测试期间初始化并在所有测试运行后关闭,您必须使用以下 STATIC 方法,并且您知道我不能再使用我的类了。 下面的方法会崩溃!!!
[ClassInitialize()]
public static void MyClassInitialize(TestContext testContext)
{
_serviceHost = new ServiceHost(typeof(PersonService));
_serviceHost.Open();
}
如何在 MSTest 中运行所有测试后初始化我的服务主机一次并关闭?
感谢您的任何建议
【问题讨论】:
-
“崩溃”是什么意思?你能更具体一点你遇到什么问题吗?是编译器错误还是堆栈跟踪?
标签: c# wcf unit-testing mstest