- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我认为这些属性的全部目的是每个程序集仅运行一次。我有一个简单的类,如下所示:
[TestClass]
public class AssemblyIntegrationTestSetup
{
public AssemblyIntegrationTestSetup() { }
public TestContext TestContext { get; set; }
[AssemblyInitialize]
public static void SetupIntegrationTests(TestContext context)
{
WindowsServiceService.Instance.StartService("Distributed Transaction Coordinator");
}
[AssemblyCleanup]
public static void TeardownIntegrationTests()
{
WindowsServiceService.Instance.StopService("Distributed Transaction Coordinator");
}
}
AssemblyInitialize
Class1.TestInitialize
Class1.TestMethod1
Class1.TestCleanup
AssemblyInitalize <-- //This shouldn't be happening right?
Class2.TestInitialize
Class2.TestMethod1
Class2.TestCleanup
Class2.TestInitialize
Class2.TestMethod2
Class2.TestCleanup
Class5.TestInitialize
Class5.TestMethod1
Class5.TestCleanup
Class7.TestInitialize
Class7.TestMethod1
Class7.TestCleanup
//More random bouncing around then...
AssemblyCleanup
AssemblyCleanup <-- //This shouldn't be happening right?
最佳答案
从MSDN库文章:
Important
This attribute should not be used on ASP.NET unit tests, that is, any test with [HostType("ASP.NET")] attribute. Because of the stateless nature of IIS and ASP.NET, a method decorated with this attribute might be called more than once per test run.
private int InitCount;
[AssemblyInitialize]
public static void SetupIntegrationTests(TestContext context)
{
if (InitCount++ == 0) {
WindowsServiceService.Instance.StartService("Distributed Transaction Coordinator");
}
}
[AssemblyCleanup]
public static void TeardownIntegrationTests()
{
if (--InitCount == 0) {
WindowsServiceService.Instance.StopService("Distributed Transaction Coordinator");
}
}
关于visual-studio-2008 - 为什么在同一测试项目程序集中两次调用[AssemblyInitialize]和[AssemblyCleanup]?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4029886/
我遇到一个问题,我的 [AssemblyCleanup] 方法没有被调用。 我目前正在构建一个自动化框架,并希望在我的测试前后完成一些 API 调用。从那以后,我找到了程序集初始化/清理方法,它们非常
我有一些方法用于初始化和清理我在测试中使用的数据库,但是我的具有属性 AssemblyInitialize 和 AssemblyCleanup 的方法没有触发。 有什么想法吗? [TestIn
在 Microsoft 的 UnitTesting 命名空间 (Microsoft.VisualStudio.TestTools.UnitTesting) 中,有 AssemblyInitialize
我认为这些属性的全部目的是每个程序集仅运行一次。我有一个简单的类,如下所示: [TestClass] public class AssemblyIntegrationTestSetup { p
我是一名优秀的程序员,十分优秀!