gtest 中Setup TearDown SetUpTestCase和TearDownTestCase 的区别
前言
- class Environment {
- public:
- virtual ~Environment() {}
- // Override this to define how to set up the environment.
- virtual void SetUp() {}
- // Override this to define how to tear down the environment.
- virtual void TearDown() {}
- private:
- struct Setup_should_be_spelled_SetUp {};
- virtual Setup_should_be_spelled_SetUp* Setup() { return NULL; }
- };
- class GlobalEvent2 :
- public testing::Environment
- {
- public:
- virtual void SetUp()
- {
- cout << "Before any case, Global 2" << endl;
- }
- virtual void TearDown()
- {
- cout << "After all cases done, Global 2" << endl;
- }
- };
- class GTEST_API_ Test {
- public:
- friend class TestInfo;
- // Defines types for pointers to functions that set up and tear down
- // a test case.
- typedef internal::SetUpTestCaseFunc SetUpTestCaseFunc;
- typedef internal::TearDownTestCaseFunc TearDownTestCaseFunc;
- // The d'tor is virtual as we intend to inherit from Test.
- virtual ~Test();
- // Sets up the stuff shared by all tests in this test case.
- //
- // Google Test will call Foo::SetUpTestCase() before running the first
- // test in test case Foo. Hence a sub-class can define its own
- // SetUpTestCase() method to shadow the one defined in the super
- // class.
- static void SetUpTestCase() {}
- // Tears down the stuff shared by all tests in this test case.
- //
- // Google Test will call Foo::TearDownTestCase() after running the last
- // test in test case Foo. Hence a sub-class can define its own
- // TearDownTestCase() method to shadow the one defined in the super
- // class.
- static void TearDownTestCase() {}
- // Returns true iff the current test has a fatal failure.
- static bool HasFatalFailure();
- // Returns true iff the current test has a non-fatal failure.
- static bool HasNonfatalFailure();
- // Returns true iff the current test has a (either fatal or
- // non-fatal) failure.
- static bool HasFailure() { return HasFatalFailure() || HasNonfatalFailure(); }
- // Logs a property for the current test, test case, or for the entire
- // invocation of the test program when used outside of the context of a
- // test case. Only the last value for a given key is remembered. These
- // are public static so they can be called from utility functions that are
- // not members of the test fixture. Calls to RecordProperty made during
- // lifespan of the test (from the moment its constructor starts to the
- // moment its destructor finishes) will be output in XML as attributes of
- // the <testcase> element. Properties recorded from fixture's
- // SetUpTestCase or TearDownTestCase are logged as attributes of the
- // corresponding <testsuite> element. Calls to RecordProperty made in the
- // global context (before or after invocation of RUN_ALL_TESTS and from
- // SetUp/TearDown method of Environment objects registered with Google
- // Test) will be output as attributes of the <testsuites> element.
- static void RecordProperty(const std::string& key, const std::string& value);
- static void RecordProperty(const std::string& key, int value);
- protected:
- // Creates a Test object.
- Test();
- // Sets up the test fixture.
- virtual void SetUp();
- // Tears down the test fixture.
- virtual void TearDown();
- private:
- // Returns true iff the current test has the same fixture class as
- // the first test in the current test case.
- static bool HasSameFixtureClass();
- // Runs the test after the test fixture has been set up.
- //
- // A sub-class must implement this to define the test logic.
- //
- // DO NOT OVERRIDE THIS FUNCTION DIRECTLY IN A USER PROGRAM.
- // Instead, use the TEST or TEST_F macro.
- virtual void TestBody() = 0;
- // Sets up, executes, and tears down the test.
- void Run();
- // Deletes self. We deliberately pick an unusual name for this
- // internal method to avoid clashing with names used in user TESTs.
- void DeleteSelf_() { delete this; }
- // Uses a GTestFlagSaver to save and restore all Google Test flags.
- const internal::GTestFlagSaver* const gtest_flag_saver_;
- // Often a user mis-spells SetUp() as Setup() and spends a long time
- // wondering why it is never called by Google Test. The declaration of
- // the following method is solely for catching such an error at
- // compile time:
- //
- // - The return type is deliberately chosen to be not void, so it
- // will be a conflict if a user declares void Setup() in his test
- // fixture.
- //
- // - This method is private, so it will be another compiler error
- // if a user calls it from his test fixture.
- //
- // DO NOT OVERRIDE THIS FUNCTION.
- //
- // If you see an error about overriding the following function or
- // about it being private, you have mis-spelled SetUp() as Setup().
- struct Setup_should_be_spelled_SetUp {};
- virtual Setup_should_be_spelled_SetUp* Setup() { return NULL; }
- // We disallow copying Tests.
- GTEST_DISALLOW_COPY_AND_ASSIGN_(Test);
- };
gtest 中Setup TearDown SetUpTestCase和TearDownTestCase 的区别相关推荐
- 三、pytest接口自动化之pytest中setup/teardown,setup_class/teardown_class讲解
pytest框架实现的前后置的处理(固件,夹具),很多种方式,常见的三种. 一.setup/teardown,setup_class/teardown_class 为什么需要这些功能? Class T ...
- python中setup函数的用法_python学习之setUp函数和tearDown函数
1,setUp():就是在一个类中最先被调用的函数,每次执行一个函数都要先执行这个函数,有几个函数就被调用几次,与放的位置无关,随便放到哪里都会先执行这个函数 2,tearDown():就是在一个类中 ...
- 第六:Pytest中的setup/teardown
简介 学过unittest的都知道里面用前置和后置setup和teardown非常好用,在每次用例开始前和结束后都去执行一次. 当然还有更高级一点的setupClass和teardownClass,需 ...
- 5.pytest中setup和teardown
文章目录 前言 函数级别 模块级别 类级别 前言 用过unittest的童鞋都知道,有两个前置方法,两个后置方法:分别是 setup() setupClass() teardown() teardow ...
- Pytest setup teardown
目录 如何实现xunit样式setup\teardown 模块级setup/teardown 类级别setup/teardown 方法和功能级别setup/teardown 如何实现xunit样式se ...
- Pytest测试框架(二):pytest 的setup/teardown方法
系列文章目录 Pytest测试框架(一):pytest安装及用例执行 Pytest测试框架(二):pytest 的setup/teardown方法 Pytest测试框架(三):pytest fixtu ...
- setup/teardown 的用法
# 方法级别函数 setup_method/teardown_method和setup/teardown对类有效,也位于类中,这两个效果一样,在测试类中每个测试方法前后调用一次.# 每条用例都要执行一 ...
- Cacti 插件中setup.php 文件的编写
Cacti 插件中setup.php 文件的编写 名词: 初始化函数 预定义函数 cacti 插件存放在 /plugins 目录,由setup.php与cacti 做关联调用; setup.ph ...
- vue3.0中setup使用(两种用法)
这篇文章主要介绍了vue3.0中setup使用,本文通过两种用法给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下 一.setup函数的特性以及作用 可以确定的是 V ...
最新文章
- 如何处理海量数据(上):从并发编程到分布式系统
- Python脚本导出为exe程序
- hdu 3613 扩展kmp+回文串
- Java 读取指定目录下的文件名和目录名
- MFC中SQLite数据库的使用
- splice slice
- Java进阶3. 内存回收机制
- 【常见错误】--Nltk使用错误
- react-native-router-flux 使用详解(三)
- morhpia(4)-更新
- 51Nod1344走格子
- 【设计模式】迭代器模式
- 百元百鸡 //构造结构体变量
- 苹果macbookpro多少钱_买一套可用的苹果全家桶,要花多少钱?
- ad网络标号怎么用_altium designer网络标号的作用范围
- php halt,thinkphp-调试halt
- es 多索引联合查询_ES 的跨索引查询详细讲解
- 华为云备份显示服务器异常(1008),云盘服务器异常
- 学习大数据开发零基础是不是限制,小白能否快速学会?附上学习路线图
- uc浏览器黑莓java下载安装_(黑莓软件)黑莓最新版UC浏览器下载安装!8.1最新版UC浏览器!...
热门文章
- 华为首次自曝“天才少年”成果:入职不到一年算法研究用于千万台 Mate/P 系列手机,网友:值 200 万年薪
- 算法基础系列第三章——图论之最小生成树问题
- 微信小程序校园生活小助手+后台管理系统前后分离VUE
- js隐藏显示div页面方法
- Vue+element实现图片的上传与显示
- JS 随机生成字符串 数字+字母组合
- c语言计算利息答案是0.0,ACCP北大青鸟4.0 程序逻辑和C语言实现课本后的习题和上机题目,怎么做?...
- Allegro基本规则设置指导书之Electrical Total Etch Length
- App Indexing
- iOS开发——仿微信图片浏览交互的实现(向下拖拽图片退出图片浏览器)