#include <gtest/gtest.h>
TEST(MyTestSuitName, MyTestCaseName) {
int actual = 1;
EXPECT_GT(actual, 0);
EXPECT_EQ(1, actual) << "Should be equal to one";
}
主要特点:
可移植的
Fatal和非致命的断言
简单断言信息消息: ASSERT_EQ(5, Foo(i)) << " where i = " << i;
// 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%
}
#include <cpunit>
namespace MyAssetTest {
using namespace cpunit;
CPUNIT_FUNC(MyAssetTest, test_stuff) {
int some_value = 42;
assert_equals("Wrong value!", 666, some_value);
}
// Fixtures go as follows:
CPUNIT_SET_UP(MyAssetTest) {
// Setting up suite here...
// And the same goes for tear-down.
}
}
#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));
}
主要特点:
难以置信的快:测试运行同时。
可移植的
自动测试注册
许多断言类型(Boost在xunit++上没有任何内容)
本机比较集合。
断言有三个级别:
致命错误
非致命错误
警告
李< / ul > < / >
简单的断言日志记录:Assert.Equal(-1, foo(i)) << "Failed with i = " << i;
测试日志:Log.Debug << "Starting test"; Log.Warn << "Here's a warning";