【问题标题】:MSBuild hangs after NUnit is finishedNUnit 完成后 MSBuild 挂起
【发布时间】:2010-11-17 12:40:56
【问题描述】:

我正在尝试使用 NUnit 作为单元测试驱动程序设置 MSBuild,但在 NUnit 完成后脚本一直挂起。它似乎没有完成它的工作,让 MSBuild 继续它的工作。
我正在使用 .NET 4.0 并使用 NUnit 2.5.8。
如果我手动运行测试或使用 gui(VS2010 或 NUnit)它可以正常工作,但在 MSBuild 调用时不能。

如果能在查找错误方面提供任何帮助,或者只是提醒您在哪里寻找答案,我将不胜感激。

手动命令如下所示:
C:\....>nunit\nunit-console.exe buildbinaries\YYYY.XXXX.Extractor.Test.IntegrationTest.dll /xml=nunit.xml

和缩写的 MSBuild:

  <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />

  <!-- define folders for build output and reports -->
  <PropertyGroup>
    <BuildPath>buildbinaries\</BuildPath>
    <ReportPath>buildreports\</ReportPath>
    <ReleaseFolder>release_artefacts\</ReleaseFolder>
    <PublishFolder>c:\ZZZ Applications\published builds\</PublishFolder>
    <DeploymentFolder>\\seldclq99\ZZZ_Costanza_Dev$\</DeploymentFolder>
  </PropertyGroup>

  <PropertyGroup>
    <!-- specify assemblies that should be included in coverage report -->
    <NCoverAssemblyList>YYYY.XXXX.Extractor.Business.dll; YYYY.XXXX.Extractor.Common.dll YYYY.XXXX.Extractor.Configuration.dll YYYY.XXXX.Extractor.DAL.Access.dll YYYY.XXXX.Extractor.DAL.Facade.dll YYYY.XXXX.Extractor.Service.Contracts.dll YYYY.XXXX.Extractor.Service.dll YYYY.XXXX.Extractor.Service.Host.WebHost.dll YYYY.XXXX.Extractor.ServiceGateway.dll</NCoverAssemblyList>
  </PropertyGroup>

  <!-- define item group for deliverables -->
  <ItemGroup>
    <Binaries Include="$(BuildPath)/**/*.*" Exclude="$(BuildPath)nunit*" />
  </ItemGroup>

  <!--
  This is the default target that will be executed if MSBuild is not started
  with a specific target (this is decided by the DefaultTargets attribute in
  the root element of this XML document)
  -->
  <Target Name="BuildAndTest">
    <CallTarget Targets="SetupDirs" />
    <CallTarget Targets="Build" />
    <CallTarget Targets="UnitAndIntegrationTest" />
    <CallTarget Targets="FxCop" />
    <CallTarget Targets="CopyToReleaseFolder" />
  </Target>

  <!-- Setup folders used during the build -->
  <Target Name="SetupDirs">
    <RemoveDir Directories="$(ReportPath);$(BuildPath);$(ReleaseFolder)" ContinueOnError="true"/>
    <MakeDir Directories="$(ReportPath);$(BuildPath);$(ReleaseFolder);$(AssemblyVersionFolder)" ContinueOnError="true"/>
  </Target>

  <Target Name="Build">
    <!-- build the software using msbuild -->
    <!-- Build error in the Install build-->
    <MSBuild ContinueOnError="true" RebaseOutputs="false" Targets="Clean;Rebuild" Projects="YYYYXXXXExtractor.sln" Properties="Configuration=Release;OutDir=..\$(BuildPath)" />

  </Target>

  <!--Run the coverage stats-->
  <Target Name="UnitAndIntegrationTest">
      <Exec Command="nunit\nunit-console.exe buildbinaries\YYYY.XXXX.Extractor.Test.IntegrationTest.dll /xml=$(ReportPath)nunit.xml "/>
      <CallTarget Targets="UnitTest" />
  </Target>

  <Target Name="UnitTest">
      <Exec Command="nunit\nunit-console.exe buildbinaries\YYYY.XXXX.Extractor.Test.UnitTest.dll /xml=$(ReportPath)nunit.xml"/>
  </Target>

  <!-- Run FxCop  -->
  <!-- The ForceError.bat fires if the xml file is not found... aka an error was found -->
  <!-- The quiet command forces an Xml file ONLY if warnings or Errors are found -->
  <Target  Name="FxCop">
    <Exec  Command="..\tools\fxcop\FxCopCmd.exe /p:..\FxCopSettings.FxCop /o:$(ReportPath)fxcop.xml" />
    <Exec Condition="Exists('$(ReportPath)fxcop.xml')" Command="..\tools\fxcop\FX_Cop_Failed_Rule_Checks.bat" />

    <!--STATS: Run again but don't fail and this time run for all rules.-->
    <Exec  Command="..\tools\fxcop\FxCopCmd.exe /p:..\FxCopSettingsALLRULES.FxCop /o:$(ReportPath)fxCopAllRules.xml" />

  </Target >

【问题讨论】:

    标签: msbuild nunit


    【解决方案1】:

    我在使用 NUnit 2.5.8 时遇到了同样的问题。在 nunit 网站上有一些关于测试过程挂起的讨论。我切换到 NUnit 2.5.7,问题就消失了。

    这似乎是几周前在2.5.9 中修复的。

    【讨论】:

    • 由于未知原因 2.5.7 在我们的机器上根本没有启动。它不会加载 nunit.core.dll。所以不幸的是,这对我来说不是一个可行的解决方案。
    • 此问题在最新的 nunit 中仍未修复。如果您有兴趣,将在此处跟踪该错误:bugs.launchpad.net/nunitv2/+bug/602761
    • bugs.launchpad.net/nunitv2/+bug/602761 在 NUnit 2.6.0 中已修复。 :)
    【解决方案2】:

    自从升级到 .NET 4 后,我注意到构建服务器上的类似行为。MsBuild 似乎间歇性地挂在 NUnit、FxCop 或 Dotcover EXEC 命令上。如果您检查任务管理器,外部执行命令(例如 Nunit.exe)的进程仍然存在。如果您手动终止进程,MsBuild 会继续以愉快的方式 - 这远非理想!

    这可能是最新版本的 MsBuild 中的错误吗?在 .NET 4 升级之前,我们的构建服务器运行良好。

    【讨论】:

    【解决方案3】:

    如果您在服务器上运行 ProcessExplorer,您会注意到生成了一个名为 nunit-agent 的带外进程,该进程最终会阻塞 nunit 运行器。

    我尚未验证这在 2.5.9 中是否已修复,但它可能是一些有用的信息。

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-07-17
    • 2018-12-05
    • 1970-01-01
    • 2014-09-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多