【问题标题】:Continuous integration with GTest and Buildbot与 GTest 和 Buildbot 的持续集成
【发布时间】:2016-06-07 15:41:10
【问题描述】:

我想用 buildbot 和 gtest 设置一个持续集成服务器。我已经设法设置了在单元测试步骤之后导致以下输出的环境:

Running main() from gtest_main.cc
[==========] Running 7 tests from 3 test cases.
[----------] Global test environment set-up.
[----------] 4 tests from VectorTest
[ RUN      ] VectorTest.size_is_correct
[       OK ] VectorTest.size_is_correct (0 ms)
[ RUN      ] VectorTest.min_index
[       OK ] VectorTest.min_index (0 ms)
[ RUN      ] VectorTest.sort_is_correct
[       OK ] VectorTest.sort_is_correct (0 ms)
[ RUN      ] VectorTest.indices_of_smallest_are_correct
[       OK ] VectorTest.indices_of_smallest_are_correct (0 ms)
[----------] 4 tests from VectorTest (0 ms total)

[----------] 2 tests from MatrixTest
[ RUN      ] MatrixTest.NumberOfColumnsIsCorrect
[       OK ] MatrixTest.NumberOfColumnsIsCorrect (0 ms)
[ RUN      ] MatrixTest.NumberOfRowsIsCorrect
[       OK ] MatrixTest.NumberOfRowsIsCorrect (0 ms)
[----------] 2 tests from MatrixTest (0 ms total)

[----------] 1 test from SparseMatrix
[ RUN      ] SparseMatrix.IteratorIsCorrect

[       OK ] SparseMatrix.IteratorIsCorrect (0 ms)
[----------] 1 test from SparseMatrix (0 ms total)

[----------] Global test environment tear-down
[==========] 7 tests from 3 test cases ran. (2 ms total)
[  PASSED  ] 7 tests.
[100%] Built target unit

我希望 buildbot 解析此输出,以检查关键字 PASSED 是否存在,以便了解单元测试期间是否出现问题。

你知道怎么做吗?

【问题讨论】:

    标签: continuous-integration googletest buildbot


    【解决方案1】:

    GoogleTest 支持使用命令行选项--gtest_output 以 JUnit 格式输出 XML,大多数 CI 系统已经知道如何解析。

    不知道Buildbot 是否支持JUnit 解析。如果没有,解析 XML 结构化输出肯定比标准纯文本输出更容易。

    【讨论】:

    • 谢谢安东尼奥。我将查看 buildbot 的文档,看看是否可以进行这样的解析。
    【解决方案2】:

    为什么不检查测试程序的退出代码?如果测试通过,则为成功代码 (0),如果测试失败,则为失败代码(通常为 1)。

    【讨论】:

    • 谢谢弗拉德。当某些单元测试未通过时,为什么程序的退出代码应该是失败代码对我来说不是很清楚。例如,据我所知,CPPUNIT 的行为并非如此。仅当程序出现问题(例如异常)时,程序才应返回失败代码。但是,由于程序需要在单元测试中检测成功和失败,所以不能指望它在检测到单元测试失败时返回失败代码。实际上,该程序做得很好。他成功检测到了测试失败。
    • @Aleph 建议从 RUN_ALL_TESTS() 的 main() 结果返回:github.com/google/googletest/blob/master/googletest/docs/… 所以通常退出代码意味着所有测试是否通过。但总的来说,你是对的——由测试程序的作者决定退出代码的含义。
    猜你喜欢
    • 2011-08-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-03-08
    • 2010-09-16
    • 1970-01-01
    • 1970-01-01
    • 2012-10-21
    相关资源
    最近更新 更多