2016-06-07 144 views
2

我想用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分析此輸出,以便檢查通過關鍵字存在爲了知道如果在單元測試過程中出現問題。

你知道該怎麼做嗎?

回答

1

GoogleTest使用命令行選項--gtest_output支持JUnit格式的XML輸出,大多數CI系統已經知道如何解析。

我不知道Buildbot是否支持JUnit解析。如果不是,那麼解析XML結構化輸出肯定比標準純文本輸出更容易。

+0

謝謝安東尼奧。我會看看buildbot的文檔,看看這樣的解析是否可能。 – Aleph

1

爲什麼不檢查測試程序的退出代碼?如果測試通過,將成爲成功代碼(0),如果失敗,則成爲失敗(通常爲1)。

+0

謝謝弗拉德。我不太清楚爲什麼當某些單元測試未通過時程序的退出代碼應該是失敗代碼。例如,據我記憶,CPPUNIT的行爲並不像這樣。只有當程序中出現錯誤時,程序纔會返回失敗代碼,例如異常。但是,由於該程序預計會檢測單元測試中的成功和失敗,因此不能指望它在檢測到單元測試失敗時返回失敗代碼。事實上,該計劃很好地完成了這項工作。他成功地檢測了測試失敗。 – Aleph

+0

@Aleph建議從RUN_ALL_TESTS()的main()結果返回:https://github.com/google/googletest/blob/master/googletest/docs/V1_5_Primer.md#invoking-the-tests因此通常會退出代碼的意思是所有的測試都通過了。但總的來說,你是對的 - 這取決於測試程序的作者來決定退出代碼的含義。 – rutsky