CC.NET: 并行化NUnit测试

3
我们有三个单元测试的DLL,需要执行1个小时(分别需要30、20和10分钟)。同时运行,不超过30分钟就可以完成。
您知道如何在CC.Net中并行执行NUnit,或者在NUnit进程“内部”进行并行化执行吗?
  • 同时运行三个DLL
  • 将一个DLL中的多个测试作为并行进程运行

这个回答解决了你的问题吗?如何并行运行NUnit测试? - Michael Freidgeim
1个回答

1
我们最终通过MSBuild并行运行测试,然后将生成的(多个)测试结果文件合并成一个文件以便于报告 - CC.Net可以在构建服务器上轻松完成此操作,但对于开发人员来说,在他们自己的机器上获得有意义的结果也很好。
示例代码大致如下:
<Target Name="UnitTestDll">
  <Message Text="Testing $(NUnitFile)" />
  <ItemGroup>
    <ThisDll Include="$(NUnitFile)"/>
  </ItemGroup>
  <NUnit ToolPath="$(NUnitFolder)" Assemblies="@(ThisDll)" OutputXmlFile="$(TestResultsDir)\%(ThisDll.FileName)-test-results.xml" ExcludeCategory="Integration,IntegrationTest,IntegrationsTest,IntegrationTests,IntegrationsTests,Integration Test,Integration Tests,Integrations Tests,Approval Tests" ContinueOnError="true" />
</Target>

<Target Name="UnitTest" DependsOnTargets="Clean;CompileAndPackage">
    <Message Text="Run all tests in Solution $(SolutionFileName)" />
  <CreateItem Include="$(SolutionFolder)**\bin\$(configuration)\**\*.Tests.dll" Exclude="$(SolutionFolder)\NuGet**;$(SolutionFolder)**\obj\**\*.Tests.dll;$(SolutionFolder)**\pnunit.tests.dll">
    <Output TaskParameter="Include" ItemName="NUnitFiles" />
  </CreateItem>
  <ItemGroup>
    <TempProjects Include="$(MSBuildProjectFile)">
      <Properties>NUnitFile=%(NUnitFiles.Identity)</Properties>
    </TempProjects>
  </ItemGroup>
  <RemoveDir Directories="$(TestResultsDir)" Condition = "Exists('$(TestResultsDir)')"/>
  <MakeDir Directories="$(TestResultsDir)"/>

  <MSBuild Projects="@(TempProjects)" BuildInParallel="true" Targets="UnitTestDll" />

  <ItemGroup>
    <ResultsFiles Include="$(TestResultsDir)\*.xml" />
  </ItemGroup> 

  <NUnitMergeTask FilesToBeMerged="@(ResultsFiles)" OutputPath="$(MSBuildProjectDirectory)\TestResult.xml" />
</Target>

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接