我是CppUnit的新手。有什麼辦法可以斷言一個值必須小於零?我正在尋找類似於CPPUNIT_ASSERT_EQUAL()
的行爲。我在想可能會有一個名爲CPPUNIT_ASSERT_LESS_THAN()
的測試函數。與CppUnit做一個「小於」測試
1
A
回答
5
CPPUNIT_ASSERT(variable < 0);
怎麼樣?
3
下面我們CppUnit的測試模板是這樣評價塊:
/*
The following macros for adding test cases are available:
- CPPUNIT_TEST(memberFunction): Add a member function to the suite.
- CPPUNIT_TEST_EXCEPTION(memberFunction, exception): Add a member function to
the suite, which fails if it does not throw the specified exception type.
- CPPUNIT_TEST_FAIL(memberFunction): Add a member function to the suite that
is expected to fail (i.e., it fails if the memberFunction does not fail).
The following assert macros are available:
- CPPUNIT_ASSERT(condition): Assert that condition is true.
- CPPUNIT_ASSERT_MESSAGE(message, condition): Assert that condition is true,
and fail with message if it is not.
- CPPUNIT_FAIL(message): Fail with the given message.
- CPPUNIT_ASSERT_EQUAL(expected, actual): Assert that expected equals actual.
Note that expected and actual needs to be of the same type.
- CPPUNIT_ASSERT_EQUAL_MESSAGE(message, expected, actual): Assert that
expected equals actual, and fail with message if not.
- CPPUNIT_ASSERT_DOUBLES_EQUAL(expected, actual, delta): Assert that the
floating point values expected and actual do not differ by more than delta.
- CPPUNIT_ASSERT_THROW(expression, ExceptionType): Assert that the given
expression causes an exception of type ExceptionType to be thrown.
- CPPUNIT_ASSERT_NO_THROW(expression): Assert that the given expression does
not throw an exception.
*/
它涵蓋了大多數情況下。正如Oxley所說,CPPUNIT_ASSERT在這裏是最好的選擇,有或沒有消息。
+0
非常感謝!作爲一個新手,我需要這樣的東西。 – 2010-06-08 17:27:28
+0
總是有在線文檔:http://cppunit.sourceforge.net/doc/lastest/group___assertions.html – 2010-06-08 17:45:34
相關問題
- 1. 第一個CppUnit測試:未定義的引用CppUnit :: SourceLine :: SourceLine
- 2. 瞭解cppUnit測試
- 3. C++ CppUnit測試(CPPUNIT_ASSERT)
- 4. CppUnit測試與現有項目
- 5. 如何啓動cppunit測試?
- 6. CPPUnit如何編寫測試?
- 7. CppUnit的:運行單個測試案例
- 8. CPPUNIT:我們真的需要每個測試一個功能嗎?
- 9. 如何做單元測試爲void函數的CppUnit
- 10. 的CppUnit創建一個簡單的測試
- 11. 使用CppUnit在一個DLL上運行單元測試
- 12. 在CppUnit測試庫中鏈接
- 13. 如何將Cppunit測試遷移到GoogleTest?
- 14. CPPUnit中的測試用例選擇
- 15. 如何使用cppunit測試dll
- 16. CppUnit測試總是通過Ctest
- 17. 單元測試遺留C++代碼與CPPUnit
- 18. 只是測試一個小腳本,我做了
- 19. boost.test與CppUnit
- 20. 做一個摩卡測試ARI文件?
- 21. 在OCaml中做一個測試加倍
- 22. cppUnit在啓動每個單元測試時使用fork()嗎?
- 23. 測試與KIF一個UIAnimation
- 24. 與qttestrunner在CppUnit的
- 25. 試圖做一個與kinetic.js的旋鈕
- 26. 從CPPunit測試用例中爲規範生成參考測試文件
- 27. 與junit做測試的奇怪問題
- 28. 與testng做多線程單元測試
- 29. 是否有與測試用例的nunit的Category屬性相當的cppunit?
- 30. 了測試錯誤,當我試圖做一個拉請求
因爲在失敗的情況下不會引用變量值 – Mekk 2018-03-02 16:49:41