与GTest和Buildbot的持续集成
我想用buildbot和gtest设置一个持续集成服务器。我已经成功地建立这导致了下面的输出单元测试步骤后的环境:与GTest和Buildbot的持续集成
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分析此输出,以便检查通过关键字存在为了知道如果在单元测试过程中出现问题。
你知道该怎么做吗?
GoogleTest使用命令行选项--gtest_output
支持JUnit格式的XML输出,大多数CI系统已经知道如何解析。
我不知道Buildbot是否支持JUnit解析。如果不是,那么解析XML结构化输出肯定比标准纯文本输出更容易。
为什么不检查测试程序的退出代码?如果测试通过,将成为成功代码(0),如果失败,则成为失败(通常为1)。
谢谢弗拉德。我不太清楚为什么当某些单元测试未通过时程序的退出代码应该是失败代码。例如,据我记忆,CPPUNIT的行为并不像这样。只有当程序中出现错误时,程序才会返回失败代码,例如异常。但是,由于该程序预计会检测单元测试中的成功和失败,因此不能指望它在检测到单元测试失败时返回失败代码。事实上,该计划很好地完成了这项工作。他成功地检测了测试失败。 – Aleph
@Aleph建议从RUN_ALL_TESTS()的main()结果返回:https://github.com/google/googletest/blob/master/googletest/docs/V1_5_Primer.md#invoking-the-tests因此通常会退出代码的意思是所有的测试都通过了。但总的来说,你是对的 - 这取决于测试程序的作者来决定退出代码的含义。 – rutsky
谢谢安东尼奥。我会看看buildbot的文档,看看这样的解析是否可能。 – Aleph