我是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