hou*_*ter 287 c++ unit-testing cppunit googletest boost-test
我知道关于C++单元测试框架的建议已经存在一些问题,但所有答案都没有帮助,因为他们只是推荐其中一个框架,但没有提供有关(特征)比较的任何信息.
我认为最有趣的框架是CppUnit,Boost和新的Google测试框架.有人做过任何比较吗?
Wer*_*ght 115
一个新的播放器是Google Test(也称为Google C++测试框架),但它非常好用.
#include <gtest/gtest.h>
TEST(MyTestSuitName, MyTestCaseName) {
int actual = 1;
EXPECT_GT(actual, 0);
EXPECT_EQ(1, actual) << "Should be equal to one";
}
Run Code Online (Sandbox Code Playgroud)
主要特点:
ASSERT_EQ(5, Foo(i)) << " where i = " << i;
SCOPED_TRACE
用于子程序循环phi*_*red 107
我刚推出了自己的框架,CATCH.它仍在开发中,但我相信它已经超过了大多数其他框架.不同的人有不同的标准,但我试图覆盖大部分地方而没有太多的权衡.看看我的链接博客条目,了解品尝者.我的五大特色是:
它还具有Objective-C绑定.该项目由Github托管
Sam*_*ron 92
他们推荐文章: 探索C++单元测试框架Jungle,作者:Noel Llopis.最近的:C++测试单元框架
我还没有找到一篇将googletest与其他框架进行比较的文章.
Wer*_*ght 52
Boost测试库是一个非常好的选择,特别是如果你已经在使用Boost.
// TODO: Include your class to test here.
#define BOOST_TEST_MODULE MyTest
#include <boost/test/unit_test.hpp>
BOOST_AUTO_TEST_CASE(MyTestCase)
{
// To simplify this example test, let's suppose we'll test 'float'.
// Some test are stupid, but all should pass.
float x = 9.5f;
BOOST_CHECK(x != 0.0f);
BOOST_CHECK_EQUAL((int)x, 9);
BOOST_CHECK_CLOSE(x, 9.5f, 0.0001f); // Checks differ no more then 0.0001%
}
Run Code Online (Sandbox Code Playgroud)
它支持:
PS:我写了一篇关于它的文章可能会帮助你入门:C++单元测试框架:一个Boost测试教程
mos*_*ald 15
我最近发布了xUnit ++,特别是作为Google Test和Boost Test Library的替代品(查看比较).如果您熟悉xUnit.Net,那么您已准备好使用xUnit ++.
#include "xUnit++/xUnit++.h"
FACT("Foo and Blah should always return the same value")
{
Check.Equal("0", Foo()) << "Calling Foo() with no parameters should always return \"0\".";
Assert.Equal(Foo(), Blah());
}
THEORY("Foo should return the same value it was given, converted to string", (int input, std::string expected),
std::make_tuple(0, "0"),
std::make_tuple(1, "1"),
std::make_tuple(2, "2"))
{
Assert.Equal(expected, Foo(input));
}
Run Code Online (Sandbox Code Playgroud)
主要特点:
Assert.Equal(-1, foo(i)) << "Failed with i = " << i;
Log.Debug << "Starting test"; Log.Warn << "Here's a warning";
归档时间: |
|
查看次数: |
252112 次 |
最近记录: |