.net - 在 Visual Studio 负载测试中使用 TypeMock Isolator.Swap.AllInstances<T>?

标签 .net testing mocking load-testing typemock

我有以下测试设置。

[TestClass,
Isolated]
public class TestClass
{
    public TestClass()
    {
    }

    private TestContext testContextInstance;
    public TestContext TestContext
    {
        get { return testContextInstance; }
        set { testContextInstance = value; }
    }

    [ClassInitialize,
    Isolated]
    public static void InitializeRunState(TestContext testContext)
    {
        Helpers.SetupMocks();
        //do some class init stuff
    }

    [TestInitialize]
    public void InitializeTestState()
    {
        Helpers.SetupMocks();
    }

    [TestMethod]
    public void Test()
    {
        //execute test
    }
}

Helpers.SetupMocks()方法我调用Isolator.Swap.AllInstances<T>() .

只要我不执行负载测试,它就可以很好地工作。一旦我配置了将执行 Test 的负载测试方法 TypeMock 开始抛出此异常:

TypeMock.TypeMockException: *** Can not call Swap.AllInstances() more than once on a type.

有没有办法避免这种情况?我配置有误吗?

最佳答案

免责声明我在 Typemock 工作

首先请注意,我们抛出此异常是因为多次伪造一个类型的所有实例确实没有意义,我们想让用户知道他可能犯了一个错误。
我认为问题在于,当您运行负载测试时,mstest 会并行运行测试类的几个实例。
在这种情况下,您应该将对 Isolator.Swap.AllInstances() 的调用从类设置移动到测试方法。
如果 mstest runs 不会在同一个类中并行运行测试,它可能会起作用。 不幸的是,mstest 似乎没有用于覆盖此行为的命令行参数。

关于.net - 在 Visual Studio 负载测试中使用 TypeMock Isolator.Swap.AllInstances<T>?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1206292/

相关文章:

python - 使用 Twisted 和 inlineCallbacks 进行测试

unit-testing - Mocking : Unit test question 中的依赖项太多

.net - 使用 EDMX 或 EDML 进行实体设计有什么区别?

.net - 在 VB.NET 中构建 REST 服务的教程?

firefox - Selenium 可以验证浏览器加载的 PDF 中的文本吗?

php - 如何将参数传递给 Controller ​​(测试)

ruby-on-rails - 非 ActiveRecord 模型的机械师

java - 模拟持久化类返回 IllegalArgumentException

c# - 如何获取唯一对象引用作为列表中项目的字符串

c++ - 如何更改 WebBrowser 全屏视频模式?