如何在您的TeamCity构建过程中集成MSTest [英] How to integrate MSTest in your TeamCity build process

查看:106
本文介绍了如何在您的TeamCity构建过程中集成MSTest的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在TeamCity中将MSTest作为构建过程的一部分运行?有什么陷阱?

How do I run MSTest as part of my build process in TeamCity? What are the pitfalls?

推荐答案

此答案专门针对Windows上的TeamCity 7.1,但可能适用于其他环境.

This answer is specifically for TeamCity 7.1 on Windows, but may apply to other environments.

  1. 在TeamCity构建配置中的"常规设置" 页面上
  1. 工件路径:Artifacts\MSTest => MSTest

  • 创建一个新的命令行构建步骤

  • Create a new Command Linebuild step

    1. 自定义脚本:if not exist Artifacts\MSTest mkdir Artifacts\MSTest

  • 创建一个新的MSTestbuild步骤

  • Create a new MSTestbuild step

    1. 列出程序集文件:**\bin\**\*.Tests.dll
    2. 结果文件:Artifacts\MSTest\testResults.trx
    1. List assembly files: **\bin\**\*.Tests.dll
    2. Results file: Artifacts\MSTest\testResults.trx

  • 陷阱

    在指定要运行的测试程序集时使用通配符

    尽管尚不清楚确切的工作方式,但您可以在指定要在MSTest构建步骤中运行的测试程序集时使用通配符. 错误报告已提交.

    请注意,如果您的某些测试失败,并且该构建被标记为失败,则MSTest构建步骤本身不会失败.如果您在MSTest构建步骤之后有构建步骤而又不想在测试失败的情况下运行,则这会导致问题(例如,生成已知有错误的构建的安装程序或文档可能没有意义).希望该问题将在TeamCity的更高版本中已修复.

    Be aware that if some of your tests fail and the build is marked as failed, the MSTest build step itself does not fail. This causes problems if you have build steps after the MSTest build step which you don't want to run if you have test failures (e.g. it may not make sense to produce an installer or documentation of a build you know has bugs). The problem will hopefully be fixed in later versions of TeamCity.

    如果您希望在测试失败时停止构建过程,则可以使用

    If you want your build process to stop when you have test failures, you can create a new build step that uses the TeamCity REST API to detect if the current build has been marked as failed (remember that when tests fail, the build step is not marked as failed, but the build is), and then fail the current build step explicitly. Example:

    1. 创建一个新的 Powershell 构建步骤
    1. 脚本:源代码
    2. 源代码:请参见下面的脚本
    1. Script: Source code
    2. Source code: See script below

  • 确保您新创建的构建步骤紧接在MSTest构建步骤之后
  • 确保此步骤之后的每个构建步骤均已将执行步骤设置为,前提是先前所有步骤均成功
  • Make sure your newly created build step comes immediately after your MSTest build step
  • Make sure every build step after this one has Execute step set to Only if all previous steps were successful
  • 脚本:

    $xml = [xml](curl --request GET http://USERNAME:PASSWORD@HOSTNAME/httpAuth/app/rest/builds/%teamcity.build.id%)
    Microsoft.PowerShell.Utility\Select-Xml $xml -XPath "/build" | % { $status = $_.Node.status }
    if ($status -eq "FAILURE") {
        throw "Failing build step on purpose"
    }
    

    这篇关于如何在您的TeamCity构建过程中集成MSTest的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆