繁体   English   中英

TeamCity并行运行Nunit测试

[英]TeamCity run Nunit tests in Parallel

所以我在想,必须有更好的方法通过teamcity为.net项目运行NUnit测试。 当前,该项目的构建大约需要10分钟,而测试步骤大约需要30分钟。

我当时正在考虑将Nunit测试分为三组,分别将它们分配给不同的代理。 然后,在开始之前,请确保他们对初始构建具有依赖关系。

这是我想到的最好方法,我还应该考虑其他方法吗?
附带说明一下,是否可以在最后合并所有Nunit测试以从在3台不同机器上构建的测试中获取一份报告? 我认为除非有人想到聪明的技巧,否则这是不可能的。

对于并行运行的Nunit测试,请访问http://www.nunit.org/index.php?p=pnunit&r=2.5的 PnUnit,对于可以配置为Nunit使用Log4Net的报告,请参见此处的示例: http:// www .softwarefrontier.com / 2007/09 / using-log4net-with-nunit.html

我们设置了一个递归MSBuild脚本来同时运行单元测试dll,如下所示:

  <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" />
  </Target>

显然,您仍然仍然需要您的Compile目标(或者在我们的例子中为CompileAndPackage)来真正地首先构建测试dll。

这也给本地开发人员弄乱了您的NUnit结果,但是已经解决了这个问题,我们编写了一个工具来帮助解决此问题: https : //github.com/15below/NUnitMerger

NUnit用户现在可以在各个位置使用Parallelizable属性,以使NUnit能够并行运行测试。

例:

[Parallelizable(ParallelScope.All)]
[TestFixture]
public class LengthOfStayRestServiceAsyncTests
{
    [Test]
    public void Test1()
    {
        Assert.That(true, Is.True);
    }
}

或者更好的方法是,将其保留在测试项目的Properties\\AssemblyInfo.cs文件中:

[assembly: Parallelizable(ParallelScope.Fixtures)]

资源:
https://github.com/nunit/docs/wiki/Parallelizable-Attribute
https://templecoding.com/blog/2016/02/29/running-tests-in-parallel-with-nunit3

暂无
暂无

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

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