簡體   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