Google Test入门教程
程序员文章站
2022-06-27 20:26:22
Google Test入门教程断言Test 架构一个简单的例子断言Assert:失败后终止Expect:失败后继续ASSERT_TRUE(condition);ASSERT_FALSE(condition);ASSERT_EQ(val1, val2);ASSERT_NQ(val1, val2);失败后打印错误信息EXPECT_EQ(val1, val2) << "val1 and va2 differ;Test 架构TESTTestSuitName = 测试的函数名...
断言
Assert:失败后终止
Expect:失败后继续
ASSERT_TRUE(condition);
ASSERT_FALSE(condition);
ASSERT_EQ(val1, val2);
ASSERT_NQ(val1, val2);
失败后打印错误信息
EXPECT_EQ(val1, val2) << "val1 and va2 differ;
Test 架构
TEST
TestSuitName = 测试的函数名 + Test
TestName自定义
TEST(TestSuitName, TestName) {
...
}
Test Fixture
继承::testing::Test
TEST_F(TestFixtureName, TestName) {
...
}
class QueueTest : public ::testing:Test {
protected:
void SetUp() override;
void TearDown() override;
}
启动测试
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
一个简单的例子
test_data.h
class TestData {
public:
int val = 0;
}
test_case.h
class fooFT : public test::Test
{
protected:
void SetUp() {};
void TearDown() {};
fooTest *m_test = NULL;
};
test_case.cpp
#include "test_case.h"
#include "test_data.h"
TEST_F(fooFT, footest)
{
int val = TestData testData.val;
EXPECT_TRUE(m_test->fooTest(val));
}
test.h
class fooTest : public Foo
{
public:
bool fooTest() { return foo(); }
本文地址:https://blog.csdn.net/I_ren/article/details/107381512
下一篇: openfaas请求处理流程详解