MSBuild:在 NUnit 任务运行之前复制依赖项文件

发布于 2024-08-14 12:56:00 字数 2482 浏览 4 评论 0原文

我们正在从 MSTests 迁移到 NUnit。第一步是迁移我们所有的 UnitTests 项目,这是使用以下 msbuild 任务完成的:

<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 任务的一部分(因为我想针对不同的配置设置运行 IntegrationTests)?

We are migrating from MSTests to NUnit. The first step was to migrate all our UnitTests projects which was accomplished using the following msbuild task:

<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=""$(NUnitResultTool)\NUnitTFS.exe" -n "$(OutDir)\NUnit_TestResults.xml" -t "$(TeamProject)" -b "$(BuildNumber)" -f "%(ConfigurationToBuild.FlavorToBuild)" -p "%(ConfigurationToBuild.PlatformToBuild)" -x "$(NUnitResultTool)\NUnitToMSTest.xslt"" />

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

But i'm at a loss as to how we are going to accomplish the same with out integration tests, because we need to deploy settings and licence files to the binary folder before running the tests. So, how can i deploy files to the binary folder, preferably as a part of the NUnit task (because i want to run the IntegrationTests against different configuration setups)?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

太阳公公是暖光 2024-08-21 12:56:00

我建议创建一个新的目标,它将复制所有必需的文件并使目标 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>

I would suggest to create new one target which will copy all required files and make target RunTests dependent on new one, basically:

<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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文