teamcity测试永远不会失败

时间:2014-10-07 07:18:07

标签: unit-testing powershell teamcity

我正在为teamcity实现一个Powershell构建脚本来测试某些功能,但无法弄清楚是否报告错误。

我正在尝试遵循此描述:

https://confluence.jetbrains.com/display/TCD8/Build+Script+Interaction+with+TeamCity#BuildScriptInteractionwithTeamCity-ReportingTests

但是,虽然脚本实际上导致某些测试被注册,但它拒绝报告错误。我现在回到了基本的例子。我有以下Powershell构建步骤(错误输出:错误,脚本:源代码):

Write-Host("##teamcity[testStarted name='className.testName']")
Write-Host("##teamcity[testStdErr name='className.testName' out='error text']")
Write-Host("##teamcity[testFinished name='className.testName']")

生成的构建日志(详细):

[13:27:12]Step 1/5: Output to build log (Powershell)
[13:27:13][Step 1/5] ##teamcity[buildStatisticValue key='buildStageDuration:firstStepPreparation' value='156.0']
[13:27:13][Step 1/5] ##teamcity[buildStatisticValue key='buildStageDuration:buildStepRUNNER_18' value='0.0']
[13:27:13][Step 1/5] Starting:   C:\Windows\SysWOW64\WindowsPowerShell\v1.0\powershell.exe  -NonInteractive -ExecutionPolicy ByPass -Command - <  D:\JetBrains\buildagent\temp\buildTmp\powershell6640337654487221076.ps1
[13:27:13][Step 1/5] in directory: D:\JetBrains\buildagent\work\7e3fac8e390ca38d

[13:27:13][Step 1/5] className.testName
[13:27:13][className.testName] [Test Error Output] error text

[13:27:13][Step 1/5] Process exited with code 0
[13:27:13][Step 1/5] ##teamcity[buildStatisticValue key='buildStageDuration:buildStepRUNNER_18' value='536.0']

即。测试在teamcity中注册为执行位成功!由于'testStdErr'输出,我希望测试失败!什么是让它失败的正确方法?

谢谢, 金

1 个答案:

答案 0 :(得分:1)

您应该使用您链接的页面上列出的testFailed指令:

##teamcity[testFailed name='MyTest.test1' message='failure message' details='message and stack trace']

或者在“构建失败条件”下更改构建失败条件设置。如果您写入stderr(编辑:这是我对文档的理解),那么构建失败:

Fail build if:
[ ] an error message is logged by build runner