2010-06-08 40 views

回答

5

CPPUNIT_ASSERT(variable < 0);怎麼樣?

+0

因爲在失敗的情況下不會引用變量值 – Mekk 2018-03-02 16:49:41

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