测试自动化 2011/06/12 - 4 GTest Advanced Guide

Google Test(gtest)新手入门 gtest),也称为Google C++ Testing Framework,是一个由Google开发的开源C++测试框架,提供了多种工具来支持C++代码的单元测试。提供了多种断言方法,可以用于测试函数、代码片段的预期行为。支持自动化测试,可以方便编写测试用例,并自动运行和输出结果。支持死亡测试(Death Test),测试代码在极端或异常条件下的行为表现。提供测试夹具(Test Fixture,一种用于编写可重复执行的测试用例的机制),使得测试用例便于重用。 阅读详情

0. 杂问杂记
Unlike TestNG, GoogleTest does not use Exception to report failure/success of a test.

 

1. More assertions

Focus: to make the error message more readable.
* Exception Assertions
ASSERT_THROW( statement , exception_type );
                       ^ What's this ?
* Predicate assertion
ASSERT_PRED1(pred1, val1);
ASSERT_PRED2(pred2, val1, val2);

* ActionResult
例:

::testing::AssertionResult IsEven(int n)

Q:似乎把测试的写进了生产代码???

* Floating-point comparison(略)
* Type Assertions

 

2. Assertions placement

You can use assertions in any C++ function. In particular, it doesn't
have to be a method of the test fixture class. The one constraint is
that assertions that generate a fatal failure (FAIL* and ASSERT_*) can only be used in void-returning functions.

Note
: Constructors and destructors are not considered
void-returning functions, according to the C++ language specification,
and so you may not use fatal assertions in them.

 

3. 输出信息定制
operator << (::std::ostream &os, const T &t);
void PrintTo(const T &t, ::std::ostream *os);

GaN功率放大器设计避坑指南:从仿真到实测的Doherty PA完整流程(基于ADS 2023) 本文详细介绍了基于ADS 2023软件,从理论计算、电路仿真到版图后仿真的GaN Doherty功率放大器完整设计流程。文章聚焦C波段应用,深入剖析了负载调制网络设计、稳定性处理、版图电磁仿真等关键环节中的常见误区与工程折衷,为工程师提供了一套从设计到实测的实战避坑指南。 阅读详情

相关推荐

jetson orin nano 使用cuPCL

jetson开发板上使用pcl时,正常使用的是cpu,拖慢了整体的效率。cuPCL有一些库用于使用CUDA处理点云。

weixin_42256401的博客 1021

【单元测试】 Google Test (gtest)使用指南

Google Test 是 Google 开源的 C++ 测试框架,用于编写单元测试。

weixin_43510208的博客 3681

如何实现SOLIDWORKS阵列的“智能变更”?

有时,我们在设计一个零件时,零件上有一排阵列孔,同时零件有不同的长度,我们又希望可以做到零件长度改变时,这排孔可以按长度等距增减孔阵列的个数;或是零件长度加长或缩短时,这排孔保持个数不变,按零件长度增减孔距。 那具体要怎么做呢?接下来,我们一起来看看怎么用SOLIDWORKS中简单的操作来实现这两种智能的变更: 零件长度加长或缩短时,这排孔要按长度等距增减孔阵列的个数。 零件长度加长或缩短时,这排孔保持个数不变,按零件长度增减孔距。 那接下来,我们一起来看看怎么用简单的操作来实现这两种智能的

SOLIDWORKS艾金米 2085

gtest学习笔记

工作中统计代码覆盖率,用到了gtest。 此处为GoogleTest—AdvancedGuide的译文 此处为CoderZh的一系列gtest学习笔记 gtest愚见以为,是一个测试代码中函数的一个框架。简单的函数直接给入参,复杂的函数要继承相应的类来完成全局变量,以及各种条件的初始化,最终完成测试。 断言的一些东西可以在用到的时候搜一下 总结一些注意的点,以备以后快速上手以及阅读mesos测试用...

liujiabin blog 932

Cadence OrCAD Capture 原理图中创建差分对约束的两种常用方法

本文介绍在原理图设计阶段,添加差分对的方法。

fydar的博客 3935

YOLOv11目标检测模型性能评价指标详解,涉及混淆矩阵、F1-Score、IoU、mAP、参数量、计算量等,一文打尽所有评价指标

本文主要讲解的是计算机视觉网络模型的性能评价指标,这是每一篇论文中都需要展示的内容。熟悉每一个评价指标也能够帮助我们在训练和改进模型过程中,更好的观察模型的变化效果。

Limiiiing的博客 8416

测试自动化 2011/06/11 - 1 一个最简单的GMock测试程序HelloGMock

Google Mock使用:做一个最简单的GMock例子并运行起来(耗时约3小时)   1. 生产代码:Hello.h, SayHello.h   [root@localhost HelloGMock]# cat Hello.h #ifndef __HELLO_ #define __HELLO_ class Hello { public:         virtual vo

printf1998的专栏 2583

一张图讲透银行个人外汇业务逻辑和实操

个人外汇业务主要分为结售汇和外币兑换两类,前者满足日常跨境需求,后者因投机属性多数银行已暂停。业务核心是利用汇率波动实现货币兑换,满足支付或投资需求。交易涉及客户分类、主流币种、多种渠道和汇率计算规则,需区分直接/间接标价法判断汇率走势。银行通过"货币兑换"科目核算损益,采用期末折算确认盈亏。监管要求包括5万美元年度额度、合法渠道、真实性原则及大额申报等。随着跨境金融数字化发展,掌握基础逻辑和合规要求是安全参与外汇业务的关键。

银行信息系统应用架构详解 299

测试自动化 2011/06/11 -2

0. 杂记与杂问   Q:如果要选择性执行一些test cases,如何配置??? * Const的一些用法总结: http://topic.csdn.net/t/20030421/20/1690292.html   # 指针相关 const   int*   a   =   &b;   [1] int   const   *a   =   &b; [2] int*   co

printf1998的专栏 1023

自定义Usecase/Pipeline

Summary of Custom Usecase and Pipeline Configuration in SA8650 QCX Framework This article elaborates on the complete process of customizing a new Usecase and Pipeline based on the SA8650 QCX framework to meet OEM and Tier1 customization requirements, with

qq_39257814的博客 930

UCIE Specification详解(二)

UCIe架构概述。

Crazzy_M的博客 3343

测试驱动开发 2011-01-02

GTest   1. 就篇介绍性文章 http://apps.hi.baidu.com/share/detail/24314152   CPPUnit / CXXTest GTest   结论:GTest在多个方面明显胜出   2. GTest 官网:http://code.google.com/p/googletest/   3. first example: try

printf1998的专栏 934

基于Proximal Policy Optimization的无人机姿态控制系统的研究及Matlab实现

本文简要介绍了基于Proximal Policy Optimization算法的无人机姿态控制系统,并使用Matlab实现了一个简化版的代码。PPO算法的特点在于能够解决强化学习中的部分可观察性问题,同时还能保持策略网络更新的稳定性。本文将介绍基于Proximal Policy Optimization(PPO)算法的无人机姿态控制系统,并使用Matlab进行简化版实现。无人机姿态控制是指通过调整飞行器各部件的参数,使其保持特定角度、方向和位置的状态。本文将实现无人机的横滚姿态控制,并将其作为实现的示例。

m0_47037246的博客 717

测试自动化 2011/06/07 GMock

1. 杂问 仿gtest为VC6写的单元测试框架 http://blog.csdn.net/riag/category/115856.aspx 一篇关于gmock的导读文章:http://blog.csdn.net/learnhard/archive/2010/07/23/5757461.aspx   2. 下载 * svn checkout svn checkout http:/

printf1998的专栏 911

ssm框架搭建

这个是一个在idea上成功跑起来的ssm框架项目,保存在这里方便以后使用直接下载

RU DOS版、EFI版32bit/64bit BIOS常用工具

DOS版、EFI版的RU工具,可用来查看IO、MEM、PCI、SMBIOS等资源。亲测在EFI SHELL下可用。

测试自动化 2011/06/04 - 2

读《玩转GTest》http://www.cnblogs.com/coderzh/archive/2009/04/06/1426755.html   0. 杂问 Q:如何让VC6运行gtest1.6?   1. 生成并使用gtest库   * 生成库 # ./configure #./make   注:所有库文件在${home}/lib/.libs目录中   * 使用库

printf1998的专栏 693

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

测试自动化 2011/06/11 - 3 GTest Primer

0. 杂问杂记 Very good articles about GoogleTest/Hudson/GCC: http://meekrosoft.wordpress.com/2010/06/02/continuous-code-coverage-with-gcc-googletest-and-hudson/     Q:如何指定某些Tests被执行?(比如,类似TestNG中的自定义

printf1998的专栏 645

测试自动化 2011/06/04 - 1

1. 再次捡起GTest 以前的老资料:http://blog.csdn.net/printf1998/archive/2011/01/02/6112922.aspx 新的资源:http://www.cnblogs.com/coderzh/archive/2009/04/06/1426755.html   2. 运行GoogleTest Sample在VMware/Redhat ent

printf1998的专栏 642

好好学习,天天向上 2012/01/21

1.  JMock/JTest for XCode  今日计划: * 完成gtest在mac上的build与运行 * 完成自己的一个test,并上传到internet上新建的repository  *  完成gmock例子并上传  * 了解gtest/xcode 2. addertest.cpp Q: “endl" not working ? use "#include

printf1998的专栏 605

测试自动化 2011/06/09 GMock

1. 杂记   阅读GMock README   2. GoogleMock Features   - provides a declarative syntax for defining mocks, - can easily define partial (hybrid) mocks, which are a cross of real   and mock objects,

printf1998的专栏 576

测试自动化 2011/06/11 - 3 GTest Samples

0. 杂问杂记   1. Sample 3 * Fixture // The tests share the test fixture in the sense of code sharing, not // data sharing.  Each test is given its own fresh copy of the // fixture.  You cannot ex

printf1998的专栏 542

测试自动化 2011/06/05 - 1

读《玩转gtest》http://www.cnblogs.com/coderzh/archive/2009/04/06/1426755.html   0. 杂问 一些关于测试覆盖tool的东东:http://www.cnblogs.com/coderzh/archive/2009/03/21/1418355.html   1. 事件:TestCase事件与Test事件   总结Tes

printf1998的专栏 512

好好学习,天天向上 2012/02/02

主要目标: * 在xcode里将代码放进source forge * 了解xcode版本的gtest    1. svn setup  reference: http://wenku.baidu.com/view/0ddce819ff00bed5b9f31d0f.html * 对SVN进行修改,确定哪些文件需要check in等等  〜/.subversion/config

printf1998的专栏 464

60,534 星、七阶段流水线:CLI-Anything v0.4.0 把 GUI 软件变成 Agent 能调的 CLI

Agent 想用 Obsidian、GIMP、Blender 这类 GUI 软件,只能截屏猜坐标,又慢又脆。港大 HKUDS 的 CLI-Anything(60,534 星)换了个打法:用七阶段流水线把 GUI 软件变成 Agent 能调的 Click CLI,再配一份 SKILL.md 让 Agent 自己学会调用,通过 CLI-Hub 分发。本文盯住 Obsidian harness 拆到底:466 行主文件里的 --json 双输出、结构化错误信封、REPL 外皮与会话状态,后端模块如何调 Local

Science prince的博客 289

AI Agent Harness 平台系统(MVP)的 Spec-Kit 案例实践

本案例展示AI Agent Harness平台MVP从治理到交付的全流程闭环:通过7次连续指令,基于Spec-Kit 1.4.2实现项目章程制定、中文规范约束、需求规格定义、实施计划、任务分解与代码生成。全程遵循“治理→规格→设计→任务→实现”链路,产出8个Maven模块的可运行工程,mvn clean verify全绿。关键实践包括技术栈作为约束而非需求、测试优先、数据模型引用一致性及版本化治理,验证了在中文语境下高效落地AI辅助开发的可行性。

HarryChenj的专栏 326

Go 服务上线前检查清单:P0/P1/P2

把 P0/P1/P2 检查项落到“为什么、怎么验证、常见失败”,形成可勾选的上线清单。

JudithHuang的博客 318

AUTOSAR 实战-诊断工具 | 基于 Python 与 USB-CANFD 的 UDS 诊断测试工具设计与实现

② 0x27 安全访问的配置化实现——六类种子密钥算法怎么做成插件,新 ECU 只写配置不改代码③ 基于 YAML 的诊断测试用例工程——轮询、断言、失败策略与回归闭环的完整实践④ DTC/Event/FiM 故障报告自动化——一条命令拉全车故障,离线解析现场抓包⑤ 用 Claude Code 开发诊断测试工具——这个工具本身的人机协作开发全过程这个系列持续更新——每篇都从真实工程出发:协议事实以 ISO 14229 为准,设计决策讲清取舍,代码与配置思路都可以照着复现。诊断测试的坑,先替你踩;

阿拉斯加小野牛的博客 472
上一篇: 测试自动化 2011/06/11 - 3 GTest Samples
下一篇: 杂记 2011/06/17 -1 Make
printf1998
博客等级 码龄16年 14粉丝 196原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符  | 博主筛选后可见
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值