1

私はCppUnitを初めて使用します。値がゼロ未満でなければならないと断言する方法はありますか?と同様の動作をするものを探していCPPUNIT_ASSERT_EQUAL()ます。のような名前のテスト関数があるのではないかと思っていましたCPPUNIT_ASSERT_LESS_THAN()

4

2 に答える 2

5

どうCPPUNIT_ASSERT(variable < 0);ですか?

于 2010-06-08T17:16:19.367 に答える
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は、メッセージの有無にかかわらず、ここでの最良の選択です。

于 2010-06-08T17:24:33.903 に答える