【问题标题】:Running XUnit tests with TeamCity using MSBuild使用 MSBuild 使用 TeamCity 运行 XUnit 测试
【发布时间】:2011-11-08 20:34:14
【问题描述】:

我正在尝试让 TeamCity 在构建过程中运行 XUnit 测试。所以我创建了一个单独的文件 - MyProject.msbuild - 与 .sln 文件位于同一文件夹中,如下所示:

<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

  <UsingTask AssemblyFile="$(MSBuildProjectDirectory)\..\bin\xunit.net\xunit.runner.msbuild.dll" TaskName="Xunit.Runner.MSBuild.xunit"
             />

    <Target Name="Build">
      <MSBuild Projects="MyProject.sln" Targets="Build" Properties="Configuration=Release">
        <xunit Assembly="MyProject.Utility.Tests\bin\Release\MyProject.Utility.Tests.dll" />
      </MSBuild>
    </Target>

</Project>

但是,无论我做什么,VS2010 都讨厌我在元素中包含元素。如果我在文件上运行 MSBuild,它会告诉我更多信息:

P:\MyProject\src>c:\Windows\Microsoft.NET\Framework64\v4.0.30319\MSBuild.exe MyProject.msbuild /tv:4.0 /v:d
Microsoft (R) Build Engine Version 4.0.30319.1
[Microsoft .NET Framework, Version 4.0.30319.225]
Copyright (C) Microsoft Corporation 2007. All rights reserved.

Build started 08.11.2011 21:08:46.
Project "P:\MyProject\src\MyProject.msbuild" on node 1 (default targets).
Building with tools version "4.0".
P:\MyProject\src\MyProject.msbuild(8,9): error MSB4067: The element <xunit> beneath element <MSBuild> is unrecognized.
Done Building Project "P:\MyProject\src\MyProject.msbuild" (default targets) -- FAILED.


Build FAILED.

"P:\MyProject\src\MyProject.msbuild" (default target) (1) ->
  P:\MyProject\src\MyProject.msbuild(8,9): error MSB4067: The element <xunit> beneath element <MSBuild> is unrecognized.

    0 Warning(s)
    1 Error(s)

Time Elapsed 00:00:00.01

所以我目前的猜测是它没有以某种方式成功加载 xunit.runner.msbuild.dll - 或者我做了其他奇怪的事情。

但是,我认为如果它无法加载 xunit.runner.msbuild.dll,它会告诉我这件事。我确保该文件未被阻止(通过使用 7zip 解压缩 xunit 发行版)。

有什么想法可以让 MSBuild 吞下我的构建文件并运行测试吗?

【问题讨论】:

    标签: msbuild xunit.net msbuild-4.0


    【解决方案1】:

    你不想嵌套调用,试试这个:

    <Target Name="Build"> 
        <MSBuild Projects="MyProject.sln" Targets="Build" Properties="Configuration=Release"> 
        </MSBuild> 
        <xunit Assembly="MyProject.Utility.Tests\bin\Release\MyProject.Utility.Tests.dll" /> 
    </Target> 
    

    目标中的项目按顺序执行。

    【讨论】:

    • 嗯,这很简单。谢谢! :)
    • 别担心,顺便说一句,我可能会将测试与构建分开,并给自己一个测试目标和一个构建目标(尽管我检查的 msbuild 的示例位没有!),然后你可以选择在您想要的任何上下文中运行任何目标。
    • 谢谢,是的,我可能会朝那个方向发展。也许它也会让 TeamCity 中的代码覆盖率变得更容易。 :)
    • 我打算最终为(类似)构建、单元测试、打包、部署、冒烟测试的目标 - 目前我将最后 3 个目标包装到一个目标中(它可以工作......) .我还需要一个集成测试目标。挑战是我有很多项目可以将所有这些东西打包到
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-11-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多