2

我們正在從MSTests遷移到NUnit。第一步是要遷移的是使用下面的MSBuild任務來完成我們所有的單元測試項目:MSBuild:在NUnit任務運行之前複製相關性文件

<Target Name="RunTests"> 

    <!-- The location of the necessary tools to run nunit tests --> 
    <PropertyGroup> 
     <NUnitToolPath>C:\Program Files\NUnit 2.5.2\bin\net-2.0</NUnitToolPath> 
     <NUnitResultTool>C:\Program Files\NUnit For Team Build Version 1.2</NUnitResultTool> 
    </PropertyGroup> 

    <!-- Create a build step representing running nunit tests --> 
    <BuildStep TeamFoundationServerUrl="$(TeamFoundationServerUrl)" BuildUri="$(BuildUri)" Name="NUnitTestStep" Message="Running Nunit Tests"> 
     <Output TaskParameter="Id" PropertyName="NUnitStepId" /> 
    </BuildStep> 

    <!-- Specify which dll's to include when running tests --> 
    <CreateItem Include="$(OutDir)\Profdoc.UnitTests*.dll"> 
     <Output TaskParameter="Include" ItemName="TestAssembly" /> 
    </CreateItem> 

    <NUnit 
     Assemblies="@(TestAssembly)" 
     ToolPath="$(NUnitToolPath)" 
     OutputXmlFile="$(OutDir)\NUnit_TestResults.xml" 
     ContinueOnError="true"> 
     <Output TaskParameter="ExitCode" PropertyName="NUnitResult" /> 
    </NUnit> 

    <!-- Update the build step result based on the output from the NUnit task --> 
    <BuildStep Condition="'$(NUnitResult)'=='0'" TeamFoundationServerUrl="$(TeamFoundationServerUrl)" BuildUri="$(BuildUri)" Id="$(NUnitStepId)" Status="Succeeded" /> 
    <BuildStep Condition="'$(NUnitResult)'!='0'" TeamFoundationServerUrl="$(TeamFoundationServerUrl)" BuildUri="$(BuildUri)" Id="$(NUnitStepId)" Status="Failed" /> 

    <!-- Upload the results to TFS. --> 
    <Exec Command="&quot;$(NUnitResultTool)\NUnitTFS.exe&quot; -n &quot;$(OutDir)\NUnit_TestResults.xml&quot; -t &quot;$(TeamProject)&quot; -b &quot;$(BuildNumber)&quot; -f &quot;%(ConfigurationToBuild.FlavorToBuild)&quot; -p &quot;%(ConfigurationToBuild.PlatformToBuild)&quot; -x &quot;$(NUnitResultTool)\NUnitToMSTest.xslt&quot;" /> 

    <!-- Indicate build failure if any tests failed --> 
    <Error Condition="'$(NUnitResult)'!='0'" Text="Unit Tests Failed" /> 
</Target> 

但我在茫然,我們將如何實現與出集成測試一樣,因爲我們在運行測試之前需要將設置和許可證文件部署到二進制文件夾。那麼,如何將文件部署到二進制文件夾,最好是作爲NUnit任務的一部分(因爲我想針對不同的配置設置運行IntegrationTest)?

回答

3

我建議創建一個新的目標,這將複製所有必需的文件,使目標RunTests依賴於新的,基本上是:

<PropertyGroup> 
    <LicenseFiles>$(PathToLicenseFiles)\**\*.lcx</LicenseFiles> 
    <SettingsFiles>$(PathToConfigFiles)\**\*.config</SettingsFiles> 
</PropertyGroup> 

<ItemGroup> 
    <Files Include="$(LicenseFiles);$(SettingsFiles)" 
      Exclude="*.tmp"/> 
</ItemGroup> 

<Target Name="CopyDependencyFiles"> 
    <CopyFiles Inputs="@(Files)" Outputs="..." /> 
</Target> 

<!-- Run Integration tests after all files were copied --> 
<Target Name="RunIntegrationTests" DependsOnTargets="CopyDependencyFiles"> 
    <NUnit .. /> 
</Target> 
相關問題