【问题标题】:Using TeamCity service messages to find if a test failed and display on build log使用 TeamCity 服务消息查找测试是否失败并显示在构建日志上
【发布时间】:2020-09-16 08:38:56
【问题描述】:

我正在使用批处理文件在 TeamCity 上运行一些冒烟测试。批处理文件在我们使用的自动化框架 TestComplete 上运行我的测试。无论我的测试是否失败或通过自动化工具 TestComplete,我在 TeamCity 上的脚本始终显示成功。我想在 TeamCity 构建日志选项卡上添加测试运行信息,例如,如果我的测试由于错误而失败并给出错误,我想在构建日志上显示错误。我尝试为此使用 TeamCity 服务消息,但它没有像我预期的那样工作。也许我遗漏了什么或做错了。

这就是我使用服务消息的方式。我正在从 TeamCity 运行的 .bat 文件中输入消息。

##teamcity[testStarted name='SmokeTest1']
run SmokeTest1.bat
##teamcity[testFailed name='SmokeTest1' message='error']
##teamcity[testFinished name='SmokeTest1']

上面的代码运行我的测试并且总是说我的测试失败是基于我的'testFailed'命令。我想要的是它应该检查我的测试是否真的失败并报告是否失败(也许它可以检查一些关键字来检查我的测试是否失败)。但似乎正在发生的事情是我已经告诉它测试失败并显示消息“错误”。在运行测试之前我不知道它是否会失败。我在这里遗漏了什么吗?

另外,在下面的例子中,我们是否应该在运行测试之前输入错误?所以,如果我使用 testStdErr 并输入错误,它总是会报告该错误,而不管该错误是否真的在我的测试运行期间发生?

##teamcity[testStarted name='SmokeTest1']
run SmokeTest1.bat
##teamcity[testStdOut name='testname' out='text']
##teamcity[testStdErr name='testname' out='error text']
##teamcity[testFinished name='SmokeTest1']

请指教。欢迎所有建议。谢谢!

我已经阅读了这两个问题,但没有找到答案:

How to export TestExecute/TestComplete results to teamcity?

Viewing TeamCity service messages

【问题讨论】:

    标签: testing automation continuous-integration teamcity testcomplete


    【解决方案1】:

    您需要根据脚本返回的内容来判断测试是否失败,然后调用 testFailed 消息。

    类似这样的东西(伪代码)

        ##teamcity[testStarted name='SmokeTest1']
        ret_va = (run SmokeTest1.bat)
        if (ret_va == 1) # 1 means fail
            ##teamcity[testFailed name='SmokeTest1' message='error']
        ##teamcity[testFinished name='SmokeTest1']
    

    【讨论】:

      猜你喜欢
      • 2021-12-22
      • 1970-01-01
      • 1970-01-01
      • 2012-11-26
      • 2013-07-30
      • 1970-01-01
      • 2020-01-19
      • 2019-04-29
      • 2020-05-14
      相关资源
      最近更新 更多