0

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

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

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

4

3 回答 3

2

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

于 2019-09-13T14:30:57.177 回答
1

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

于 2012-07-02T23:13:45.917 回答
1

我们设置了一个递归 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>

你显然仍然需要你的编译目标(或者在我们的例子中是 CompileAndPackage)来实际构建测试 dll。

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

于 2012-07-31T15:38:45.343 回答