如何使用命令提示符使 MSTest 并行进行 运行 测试

How to make MSTest to run tests in parallel using the command prompt

我正在使用 img MSTest.exe 工具 运行 我的集成测试使用命令提示符(在 powershell 脚本中)。

但我发现它 运行 非常慢,我需要 运行 它更快。 查看 powershell 输出,似乎 MSTest 实际上 运行 将它们一一列出。

有没有办法 运行 它们一起或并行?

我正在运行使用此命令进行测试:

MSTest.exe "/testcontainer:C:\myTestClass.dll" "/resultsfile:C:\TestResult.trx" 

您可以为此使用测试设置。

在您的测试 dll 所在的同一文件夹中添加一个 .testsettings 文件。

您的 .testsettings 文件应如下所示(注意 Execution 元素上的“"parallelTestCount"”属性):

<TestSettings name="SecurityWebApi" id="5f0defa1-d6a5-40a6-94ae-1522a7aeeba8" xmlns="http://microsoft.com/schemas/VisualStudio/TeamTest/2010">
  <Description>These are default test settings for a local test run.</Description>
  <Execution parallelTestCount="5">
    <TestTypeSpecific>
      <UnitTestRunConfig testTypeId="13cdc9d9-dd`enter code here`b5-4fa4-a97d-d965ccfc6d4b">
        <AssemblyResolution>
          <TestDirectory useLoadContext="true" />
        </AssemblyResolution>
      </UnitTestRunConfig>
      <WebTestRunConfiguration testTypeId="4e7599fa-5ecb-43e9-a887-cd63cf72d207">
        <Browser name="Internet Explorer 7.0">
          <Headers>
            <Header name="User-Agent" value="Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)" />
            <Header name="Accept" value="*/*" />
            <Header name="Accept-Language" value="{{$IEAcceptLanguage}}" />
            <Header name="Accept-Encoding" value="GZIP" />
          </Headers>
        </Browser>
      </WebTestRunConfiguration>
    </TestTypeSpecific>
    <AgentRule name="LocalMachineDefaultRole">
    </AgentRule>
  </Execution>
  <Properties />
</TestSettings>

然后在你的命令中你可以这样使用它:

MSTest.exe "/testcontainer:C:\myTestClass.dll" "/runsettings:yourfile.runsettings" "/resultsfile:C:\TestResult.trx"