3

We have 3 DLL of unit tests that take 1 hour to execute (30, 20 and 10 minutes each). Ran simultaneously, it takes no much more than 30 min.

Do you know if it's possible, and how, to parallelize execution of NUnit in CC.Net, or "inside" NUnit process :

  • run the 3 DLL in same time

or,

  • run many tests in 1 DLL as parallel processes
Francois
  • 10,730
  • 7
  • 47
  • 80
  • Does this answer your question? [How can I run NUnit tests in parallel?](https://stackoverflow.com/questions/3313163/how-can-i-run-nunit-tests-in-parallel) – Michael Freidgeim Jun 11 '20 at 10:13

1 Answers1

1

We ended up running our tests in parallel via MSBuild, and then merging the resulting (multiple) test result files into a single file for ease of reporting - CC.Net will happily do that for you on the build server, but it's nice for the devs to have meaningful results on their own machines as well.

Example code looks something like:

<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>
mavnn
  • 9,101
  • 4
  • 34
  • 52