gtest 过滤 选择部分测试用例执行

2024-06-09 14:18

本文主要是介绍gtest 过滤 选择部分测试用例执行,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

包含main函数的gtest源文件编译为可执行程序spider,使用gtest_filter命令行参数过滤case2测试用例关联的所有测试项:
./spider --gtest_filter=case2.*

CutOneVertex为测试项(TEST(tc_linked_directiongraph, CutOneVertex))
./spider --gtest_filter=*CutOneVertex

int main(int argc, char ****argv**) {testing::InitGoogleTest(&argc, **argv**);rc = RUN_ALL_TESTS();return rc;
}

[uxdb@localhost backend]$ ./spider --gtest_filter=tc_linked_directiongraph_5vertex_5edge_1circle.*
<<<<<<<<<<<< Running main() from spider.cc
<<<<<<<<<<<< notice - initialize uxdb master environment … done
Note: Google Test filter = tc_linked_directiongraph_5vertex_5edge_1circle.*
[==========] Running 1 test from 1 test suite.
[----------] Global test environment set-up.
[----------] 1 test from tc_linked_directiongraph_5vertex_5edge_1circle
[ RUN ] tc_linked_directiongraph_5vertex_5edge_1circle.FindPathBetweenTwoVertex

[ OK ] tc_linked_directiongraph_5vertex_5edge_1circle.FindPathBetweenTwoVertex (0 ms)
[----------] 1 test from tc_linked_directiongraph_5vertex_5edge_1circle (0 ms total)

[----------] Global test environment tear-down
[==========] 1 test from 1 test suite ran. (0 ms total)
[ PASSED ] 1 test.

其实在命令行带/?参数执行编译好的测试程序,就知道gTest这些开关:
附在下面
This program contains tests written using Google Test. You can use the
following command line flags to control its behavior:

Test Selection:
–gtest_list_tests
List the names of all tests instead of running them. The name of
TEST(Foo, Bar) is “Foo.Bar”.
gtest_filter=POSTIVE_PATTERNS[-NEGATIVE_PATTERNS]
Run only the tests whose name matches one of the positive patterns but
none of the negative patterns.
‘?’ matches any single character;
‘*’ matches any substring;
‘:’ separates two patterns.
–gtest_also_run_disabled_tests
Run all disabled tests too.

[uxdb@localhost backend]$ ./spider /?
<<<<<<<<<<<< Running main() from spider.cc
This program contains tests written using Google Test. You can use the
following command line flags to control its behavior:

Test Selection:
–gtest_list_tests
List the names of all tests instead of running them. The name of
TEST(Foo, Bar) is “Foo.Bar”.
–gtest_filter=POSTIVE_PATTERNS[-NEGATIVE_PATTERNS]
Run only the tests whose name matches one of the positive patterns but
none of the negative patterns. ‘?’ matches any single character; ‘*’
matches any substring; ‘:’ separates two patterns.
–gtest_also_run_disabled_tests
Run all disabled tests too.

Test Execution:
–gtest_repeat=[COUNT]
Run the tests repeatedly; use a negative count to repeat forever.
–gtest_shuffle
Randomize tests’ orders on every iteration.
–gtest_random_seed=[NUMBER]
Random number seed to use for shuffling test orders (between 1 and
99999, or 0 to use a seed based on the current time).

Test Output:
–gtest_color=(yes|no|auto)
Enable/disable colored output. The default is auto.
–gtest_print_time=0
Don’t print the elapsed time of each test.
–gtest_output=(json|xml)[:DIRECTORY_PATH/|:FILE_PATH]
Generate a JSON or XML report in the given directory or with the given
file name. FILE_PATH defaults to test_detail.xml.
–gtest_stream_result_to=HOST:PORT
Stream test results to the given server.

Assertion Behavior:
–gtest_death_test_style=(fast|threadsafe)
Set the default death test style.
–gtest_break_on_failure
Turn assertion failures into debugger break-points.
–gtest_throw_on_failure
Turn assertion failures into C++ exceptions for use by an external
test framework.
–gtest_catch_exceptions=0
Do not report exceptions as test failures. Instead, allow them
to crash the program or throw a pop-up (on Windows).

Except for --gtest_list_tests, you can alternatively set the corresponding
environment variable of a flag (all letters in upper-case). For example, to
disable colored text output, you can either specify --gtest_color=no or set
the GTEST_COLOR environment variable to no.

For more information, please read the Google Test documentation at
https://github.com/google/googletest/. If you find a bug in Google Test
(not one in your own code or tests), please report it to
googletestframework@googlegroups.com.
<<<<<<<<<<<< notice - initialize uxdb master environment … done
[uxdb@localhost backend]$

这篇关于gtest 过滤 选择部分测试用例执行的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1045414

相关文章

C++统计函数执行时间的最佳实践

《C++统计函数执行时间的最佳实践》在软件开发过程中,性能分析是优化程序的重要环节,了解函数的执行时间分布对于识别性能瓶颈至关重要,本文将分享一个C++函数执行时间统计工具,希望对大家有所帮助... 目录前言工具特性核心设计1. 数据结构设计2. 单例模式管理器3. RAII自动计时使用方法基本用法高级用法

Java实现远程执行Shell指令

《Java实现远程执行Shell指令》文章介绍使用JSch在SpringBoot项目中实现远程Shell操作,涵盖环境配置、依赖引入及工具类编写,详解分号和双与号执行多指令的区别... 目录软硬件环境说明编写执行Shell指令的工具类总结jsch(Java Secure Channel)是SSH2的一个纯J

python 线程池顺序执行的方法实现

《python线程池顺序执行的方法实现》在Python中,线程池默认是并发执行任务的,但若需要实现任务的顺序执行,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋... 目录方案一:强制单线程(伪顺序执行)方案二:按提交顺序获取结果方案三:任务间依赖控制方案四:队列顺序消

Go语言连接MySQL数据库执行基本的增删改查

《Go语言连接MySQL数据库执行基本的增删改查》在后端开发中,MySQL是最常用的关系型数据库之一,本文主要为大家详细介绍了如何使用Go连接MySQL数据库并执行基本的增删改查吧... 目录Go语言连接mysql数据库准备工作安装 MySQL 驱动代码实现运行结果注意事项Go语言执行基本的增删改查准备工作

解密SQL查询语句执行的过程

《解密SQL查询语句执行的过程》文章讲解了SQL语句的执行流程,涵盖解析、优化、执行三个核心阶段,并介绍执行计划查看方法EXPLAIN,同时提出性能优化技巧如合理使用索引、避免SELECT*、JOIN... 目录1. SQL语句的基本结构2. SQL语句的执行过程3. SQL语句的执行计划4. 常见的性能优

Spring Bean初始化及@PostConstruc执行顺序示例详解

《SpringBean初始化及@PostConstruc执行顺序示例详解》本文给大家介绍SpringBean初始化及@PostConstruc执行顺序,本文通过实例代码给大家介绍的非常详细,对大家的... 目录1. Bean初始化执行顺序2. 成员变量初始化顺序2.1 普通Java类(非Spring环境)(

Spring Boot 中的默认异常处理机制及执行流程

《SpringBoot中的默认异常处理机制及执行流程》SpringBoot内置BasicErrorController,自动处理异常并生成HTML/JSON响应,支持自定义错误路径、配置及扩展,如... 目录Spring Boot 异常处理机制详解默认错误页面功能自动异常转换机制错误属性配置选项默认错误处理

如何在Java Spring实现异步执行(详细篇)

《如何在JavaSpring实现异步执行(详细篇)》Spring框架通过@Async、Executor等实现异步执行,提升系统性能与响应速度,支持自定义线程池管理并发,本文给大家介绍如何在Sprin... 目录前言1. 使用 @Async 实现异步执行1.1 启用异步执行支持1.2 创建异步方法1.3 调用

Spring Boot Maven 插件如何构建可执行 JAR 的核心配置

《SpringBootMaven插件如何构建可执行JAR的核心配置》SpringBoot核心Maven插件,用于生成可执行JAR/WAR,内置服务器简化部署,支持热部署、多环境配置及依赖管理... 目录前言一、插件的核心功能与目标1.1 插件的定位1.2 插件的 Goals(目标)1.3 插件定位1.4 核

mybatis执行insert返回id实现详解

《mybatis执行insert返回id实现详解》MyBatis插入操作默认返回受影响行数,需通过useGeneratedKeys+keyProperty或selectKey获取主键ID,确保主键为自... 目录 两种方式获取自增 ID:1. ​​useGeneratedKeys+keyProperty(推