作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我最近一直在与 Moles 合作,现在我正在转向 Fakes。在我的旧测试项目中,我有一个测试设置,如下所示:
[TestInitialize]
public void Setup()
{
//...
}
[TestMethod]
[HostType("Moles")]
public void MolesTestMethod()
{
//...
}
[TestMethod]
public void FakesTestMethod()
{
using (ShimsContext.Create())
{
//...
}
}
-- C#:
using Microsoft.QualityTools.Testing.Fakes;
using(ShimsContext.Create())
{
// your test code using Shims here
}
-- VisualBasic.NET
Imports Microsoft.QualityTools.Testing.Fakes
Using ShimsContext.Create
' your test code using Shims here
End Using
[TestInitialize]
public void Setup()
{
using(ShimsContext.Create())
{
//...
}
}
[TestMethod]
public void PerformActionFromConfigActionStateActionIdIsSet()
{
using (ShimsContext.Create())
{
Setup();
//...
}
}
最佳答案
Defines a scope, outside of which an object or objects will be disposed.
ShimsContext.Create()
创建 IDisposable 实例并用 using block 包装它。在初始化您的 Fakes 类并离开使用范围后,您的配置将被释放。
[TestClass]
public class TestClass1
{
protected static IDisposable Context { get; set; }
[ClassInitialize]
public static void ClassInitialize(TestContext testContext)
{
// Create ShimsContext
Context = ShimsContext.Create();
// TODO: Additional setup
}
[ClassCleanup]
public static void ClassCleanup()
{
Context.Dispose();
Context = null;
}
[TestMethod]
public void TestMethod1()
{
// Fakes should be initialized correctly here
}
[TestMethod]
public void TestMethod2()
{
// Fakes should be initialized correctly here
}
}
关于unit-testing - 痣/假货 : How do I implement a test setup?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12017711/
我是一名优秀的程序员,十分优秀!