简体   繁体   English

Visual Studio 2013测试运行程序(VSTest)大大降低了测试执行速度

[英]Visual Studio 2013 Test Runner (VSTest) slows tests execution dramatically

I have a test suite that is using Visual Studio Unit Test framework. 我有一个使用Visual Studio单元测试框架的测试套件。 It was initially developed on .NET 4.0 in VS2010. 它最初是在VS2010的.NET 4.0上开发的。
After upgrade to .NET 4.5/VS2013 (no logic changes, just bumping .NET version in csproj files) same tests run x2 times slower. 升级到.NET 4.5 / VS2013(无逻辑更改,只是在csproj文件中增加.NET版本)之后,相同的测试运行速度慢了2倍。 It happens both when executed within IDE or from console (vsconsole/vstest). 无论是在IDE中执行还是从控制台(vsconsole / vstest)执行,都会发生这种情况。
After I port few upgraded tests to use NUnit, execution times are back to normal @4.5/2013. 在我移植了一些升级的测试以使用NUnit之后,执行时间回到了@ 4.5 / 2013。 I have absolutely no idea what is the root cause and how to fix this. 我完全不知道根本原因是什么以及如何解决此问题。 The primary suspect was InIsolation parameter for VSTest, but it doesn't seem to have any effect on execution time. 主要怀疑对象是VSTest的InIsolation参数,但似乎对执行时间没有任何影响。 Any ideas about all of the above? 关于上述所有想法? I can't port all tests because there are a lot of them and this approach will require much additional efforts on changing of build scripts. 我无法移植所有测试,因为其中有很多测试,而这种方法在更改构建脚本方面需要付出更多的努力。

It turned out Shims infrastructure has major performance overhead when a lot of classes are generated. 事实证明,当生成许多类时,Shims基础结构会带来很大的性能开销。 We solved the problem by creating explicit "no shims" context for method that doesn't use them and marking only required classes to have shims generated: 我们通过为不使用它们的方法创建显式的“无垫片”上下文并仅标记要生成垫片的必需类来解决该问题:

/// <summary>
/// Executing method without ShimsContext being created.
/// </summary>
/// <param name="action">Action to execute.</param>
/// <remarks>Usage: ExecuteWithoutShimsContext(()=> TestMethod()); </remarks>
public static void ExecuteWithoutShimsContext(FakesDelegates.Action action)
{
    if (action == null)
    {
        throw new ArgumentNullException("action");
    }
    using (UnitTestIsolationRuntime.AcquireProtectingThreadContext())
    {
        action();
    }
}

System.fakes configuration file example: System.fakes配置文件示例:

<Fakes xmlns="http://schemas.microsoft.com/fakes/2011/">
  <Assembly Name="System" Version="4.0.0.0"/>
    <ShimGeneration>
        <Clear/>
        <Add FullName="System.Diagnostics.Process"/>
        <Add FullName="System.Net.Sockets.TcpClient"/>
        <Add FullName="System.Net.Sockets.NetworkStream"/>
        <Add FullName="System.ComponentModel.BackgroundWorker"/>
        <Add FullName="System.ComponentModel.Component"/>
        <Add FullName="System.Timers.Timer"/>
    </ShimGeneration>
</Fakes>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM