gtest 学习之五 测试用例中定义类
2015-06-13 22:02
288 查看
上一个例子中被测试的类是作为测试类的一个成员变量,在本例中没有测试类,被测试类只能在一个测试用例中定义使用
头文件sample4.h
main.cpp:
运行结果:
头文件sample4.h
#ifndef GTEST_SAMPLES_SAMPLE4_H_ #define GTEST_SAMPLES_SAMPLE4_H_ // A simple monotonic counter. class Counter { private: int counter_; public: // Creates a counter that starts at 0. Counter() : counter_(0) {} // Returns the current counter value, and increments it. int Increment(); // Prints the current counter value to STDOUT. void Print() const; }; #endif // GTEST_SAMPLES_SAMPLE4_H_
main.cpp:
#include "gtest/gtest.h" #include "sample4.h" TEST(Counter, Increment) { Counter c;//在测试用例中定义变量 // EXPECT_EQ() evaluates its arguments exactly once, so they // can have side effects. EXPECT_EQ(0, c.Increment()); EXPECT_EQ(1, c.Increment()); EXPECT_EQ(2, c.Increment()); } int main(int argc, char *argv[]) { testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); }
运行结果:
相关文章推荐
- 作为程序员必须要了解的位,字节,kb,mb,gb
- 由LCA引发的问题--RMQ,Tarjan,并查集等
- zbar 的VS2013移植
- The method findViewById(int) is undefined for the type FragmentHome报错
- SSH学习——声明式事物管理(Spring)
- 第53章、Matrix图形处理(从零开始学Android)
- STM32外部中断
- NOIP2013 货车运输
- jsp——学习篇:简单使用CSS
- Geany的"跳转到标记定义“功能如何使用
- CF#306(Div. 2) E-Brackets in Implications
- 一、SpringMvc基础
- 面向对象程序设计
- ios开发 数据存储
- 第三章 选择结构(一)
- 第52章、Bitmap图像处理(从零开始学Android)
- 如何利用PC机搭建综合实验环境之Vmware workstation篇
- NOIP2013 花匠
- Mac OS X Git安装教程
- XJOI NOI2015训练题7 题解