/*************************************************************
*使用gtest自动化测试
*
*************************************************************/
[依赖项]
 
eclips KEPLER
 
cygwin 
 
window xp
 
gtest库
 
cmd已是管理员权限
 
[gtest 搭建]
 
 a)、首先确定已成功安装好了eclips C++ 开发相关的工具,并确定g++的环境变量已能正常使用
 
 b)、打开eclips,新建两个项目,gtest(appliction),testlibs(static library),
 
 c)、解压gtest库,copy (include,src)到新建好的gtest目录中
 
 d)、排除库文件的编译 gtest库中的所有文件,选中gtest项目中的include文件夹,右键->属性-> c/c++build -> 选中exclude resouce form build,再用同样的方法去掉src文件夹的编译设置
 
e)、设置编译头文件,选中gtest项目->右键->属性->c/c++
  
1)、选中setting -> 选中tool settings -> 选中 cross g++ compiler -> 选中includes ->添加include paths 
   
"${workspace_loc:/${ProjName}/include}",
   "${workspace_loc:/${ProjName}}",
   "${workspace_loc:/testlibs}"
 
  2)、点击apply,再点ok
 
 f)、在gtest项目中新增加一个main.cc文件并输入下面的代码
 
//-------------------------------
#include "gtest/gtest.h"
#include "src/gtest_main.cc"
#include "src/gtest-all.cc"
//-------------------------------
 
 g)、选中gtest项目中的include文件夹,右键->属性->c/c++build -> 选中build steps 在post-build steps的command中输入"..\auto_test.bat"
 
h)、编写脚本
 
1)、向gtest项目中增加一个auto_test.bat文件
 
2)、输入脚本
 
@gtest.exe > out.log
 
 I)、在testlibs中写入目标代码(新建了一个class类的声明和定义)
 
test-class.h:
//code begin-----------------------
#ifndef TEST_CLASS_H_
#define TEST_CLASS_H_
 
class test_class{
public:
 int write();
};
 
#endif /* TEST_CLASS_H_ */
//code  end-------------------------
 
test-class.cc:
//code begin------------------------
#include "test-class.h"
 
int test_class::write(){
 return 10;
}
//code end------------------------
 
 J)、在gtest项目中编写测试用列(添加test.cc)
 
test.cc:
//------------------------
#include "gtest/gtest.h"
#include <test-class.h>
 
TEST(TESTCASE,TEST){
 test_class test;
 //test.write();
 EXPECT_EQ(10,test.write());
}
 
 
TEST(TESTCASE1,TEST1){
 FAIL(); //手动增加一个失败的测试
}
//------------------------
 
 k)正常编译gtest项目
 
 l)、打开eclips的console,就会看到测试输出的一些信息,那就是测试报告
 
console:
//------------------------
Running main() from gtest_main.cc
[==========] Running 1 test from 1 test case.
[----------] Global test environment set-up.
[----------] 1 test from TESTCASE
[ RUN      ] TESTCASE.TEST
[       OK ] TESTCASE.TEST (0 ms)
[----------] 1 test from TESTCASE (30 ms total)
 
[----------] Global test environment tear-down
[==========] 1 test from 1 test case ran. (30 ms total)
[  PASSED  ] 1 test.
 
[性能测试 搭建]
 
a) 修改gtest项目属性
 
1)、选中gtest项目(alt+enter)->打开(c/c++ build 节点)-> setting-> cross g++ compiler 
 
2)、修改command 原为 g++ ,改为 g++ -pg
 
3)、打开(cross g++ linker) -> 修改command 原为 g++ ,改为 g++ -pg
 
b) 修改testlibs项目属性
 
1)、选中testlibs项目(alt+enter)->打开(c/c++ build 节点)-> setting-> cross g++ compiler 
 
2)、修改command 原为 g++ ,改为 g++ -pg
 
3)、打开(cross g++ linker) -> 修改command 原为 g++ ,改为 g++ -pg
 
c)、修改脚本auto_test.bat
 
::修改out的值就可以开启和关闭是否执行测试 0为开启用
//code begin-----------------
@set out=1
 
::gtest文件输出格式0 txt,1 xml
@set testOutType=0 
 
::test日志文件输出文件名
@set log="out.log";
@if %testOutType%==1 then  ( %log%="out.xml")
 
@if "%out%"==0 then goto lable1 else goto lable2 
 
:lable1
@echo "---------start unit test----"
@echo "---------unit test results----------">log
::@gtest.exe --gtest_output="xml:%log%"
@gtest.exe >log
@echo "---------Performance Test Results----------">>log
@if exist "gmon.out" (goto lable3) else (goto lable4)
:lable3
@(gprof gtest.exe gmon.out -b) >>log 
@echo "---------test complet----------">>log
@cat log
@echo "Full output has been output to a log file."
::open log file
@notepad log
 
:lable2
@echo "">log
goto exit;
 
:lable4
@goto exit;
 
::exit script
:exit
@exit(0)
//code end-----------
 
d)、打开consol 窗口,生成项目:选中项目 (ctrl+b),编译操作完成后会自己打测试报告
 
e)、查看性能测试报告
 
"---------Performance Test Results----------"
Flat profile:
 
Each sample counts as 0.01 seconds.
  %   cumulative   self              self     total           
 time   seconds   seconds    calls  Ts/call  Ts/call  name    
 19.16      1.40     1.40                             xis_data::set_data(xis_data const&)
 18.96      2.77     1.38                             xis_data_array::append(xis_data)
 
Call graph
 
 
granularity: each sample hit covers 4 byte(s) for 0.14% of 7.28 seconds
 
index % time    self  children    called     name
                                                 <spontaneous>
[1]     19.2    1.40    0.00                 xis_data::set_data(xis_data const&) [1]
-----------------------------------------------
                                                 <spontaneous>
[2]     19.0    1.38    0.00                 xis_data_array::append(xis_data) [2]
-----------------------------------------------
                                                 <spontaneous>
 
"---------end Performance Test Results----------"
 
f)、输出报告包括(单元测试、性能测试)
 
console:
//------------------------
Running main() from gtest_main.cc
[==========] Running 1 test from 1 test case.
[----------] Global test environment set-up.
[----------] 1 test from TESTCASE
[ RUN      ] TESTCASE.TEST
[       OK ] TESTCASE.TEST (0 ms)
[----------] 1 test from TESTCASE (30 ms total)
 
[----------] Global test environment tear-down
[==========] 1 test from 1 test case ran. (30 ms total)
[  PASSED  ] 1 test.
 
"---------Performance Test Results----------"
Flat profile:
 
Each sample counts as 0.01 seconds.
  %   cumulative   self              self     total           
 time   seconds   seconds    calls  Ts/call  Ts/call  name    
 19.16      1.40     1.40                             xis_data::set_data(xis_data const&)
 18.96      2.77     1.38                             xis_data_array::append(xis_data)
 
Call graph
 
 
granularity: each sample hit covers 4 byte(s) for 0.14% of 7.28 seconds
 
index % time    self  children    called     name
                                                 <spontaneous>
[1]     19.2    1.40    0.00                 xis_data::set_data(xis_data const&) [1]
-----------------------------------------------
                                                 <spontaneous>
[2]     19.0    1.38    0.00                 xis_data_array::append(xis_data) [2]
-----------------------------------------------
                                                 <spontaneous>
 
"---------end Performance Test Results----------"
 
g)、关闭报告,测试结束 (一定要操作这一步,否则eclips会无法操作)

使用gtest自动化测试并给出性能测试结果(windows 版本,版本平台也可以使用,但并没有做完整的测试)的更多相关文章

  1. 使用AS编译jni文件无法编译出arm64-v8a,x86_64和mips64平台的.so文件的解决方法

    我用的插件版本是:classpath 'com.android.tools.build:gradle-experimental:0.4.0',AS集成和使用ndk编译项目参考官方demo:https: ...

  2. 《selenium2 python 自动化测试实战》(11)——selenium安装版本

    先和大家说一下selenium环境的问题,大家可以在cmd里先看一下自己的selenium版本: 回车,就可以安装了. 本来想和大家说如何跳过验证码进行登录的,结果好多朋友加我问我环境配置的问题,所以 ...

  3. gtest 自动化测试 部署

    1.部署 a)编译框架 1.1下载gtest库1.6.0 并解压到文件夹 "/user/{user}/gtest.1.6.0" 下载地址:https://code.google.c ...

  4. web自动化测试,弹出窗的操作

    弹出窗有两种: 1.alert弹窗 2.页面弹出窗 什么是alert弹窗呢,点击某一个事件后,会弹出一个弹窗,如下图所示,相信大家在测试中有遇到过,怎么操作它呢 1.1弹窗出现后,使用switch_t ...

  5. 【CefSharp】 禁用右键菜单 与 控制弹出窗口的方式(限版本39.0.0.1)

    这周没什么时间,一开始就在忙一些CefSharp的事情,Win10的研究就放了下来,CefSharp的资料挺少的,但好在是开源的,可以我们便宜的折腾.因为两个的内容都不多,我就合成一篇文章啦. 这还里 ...

  6. 解决Windows Server2008 R2中IE开网页时弹出阻止框(Windows Server2008网页无法打开的问题)

    相信使用Windows Server2008的朋友都遇到过这种情况,用IE打开网站时会弹出“Internet Explorer增强安全配置正在阻止来自下列网站的此应用程序中的内容”的对话框.如下图所示 ...

  7. WPF窗体视图中绑定Resources文件中字符串时,抛出:System.Windows.Markup.StaticExtension

    问题描述: 在Resources.resx定义了一个静态字符串字段Title,并在WPF窗体视图中绑定为窗体的标题: Title="{x:Static local:Resources.Tit ...

  8. 解决微信官方SDK给出1.4.0等版本没有预览文件(previewFile)等接口

    使用苹果手机测试 调用微信的js-sdk在系统中实现上传.预览附件的功能.在自己的手机测试通过后,直接丢给QA测试了 本以为相安无事了,没想到QA用安卓手机测的时候居然不得,使用的是下载下来的jwei ...

  9. loadrunner性能测试---添加windows多台压力机

    添加多台压力机 1.前置条件 1)保证压力机上都安装了loadrunner Agent,并启动,状态栏中会有小卫星.       2)添加的压力机与controller所在机器是否在同一个网段,建议关 ...

随机推荐

  1. Entity Framework(三)---FluentAPI和增删查改

    一.FluentAPI: 1.基本配置: namespace ConsoleApp14.ModelConfig { public class PersonConfig: EntityTypeConfi ...

  2. 孤荷凌寒自学python第二十五天初识python的time模块

    孤荷凌寒自学python第二十五天python的time模块 (完整学习过程屏幕记录视频地址在文末,手写笔记在文末) 通过对time模块添加引用,就可以使用python的time模块来进行相关的时间操 ...

  3. cloud-init介绍及源码解读

    https://zhuanlan.zhihu.com/p/27664869 知乎大神写的  

  4. 【志银】MySQL命令总结

    ===0-MySQL密码设置===0.1-登入和进入MySQL数据库: 0.1.1-登入MySQL数据库:C:\Users\Administrator>mysql -u用户名 -hMySQL服务 ...

  5. 【转载】10个最佳ES6特性

    译者按: 人生苦短,我用ES6. 原文: Top 10 ES6 Features Every Busy JavaScript Developer Must Know 译者: Fundebug 为了保证 ...

  6. BI商业智能培训系列——(三)SSAS入门

    简介:     一个客户端工具,提供了设计.创建和管理来自数据仓库的多维数据集的功能,还提供对OLAP数据客户端访问功能. 解决方案如下: 相关概念: 维度: 维度可以理解为划分依据,简单的说就是看问 ...

  7. group_load,weight_load,group_capacity, group_weight大致都是啥数值

    [ 113.180820] sgs->group_load:2039,sum_nr_running:2,sum_weighted_load:2039,sgs->group_capacity ...

  8. linux sed讲解

    1.sed 查找替换 显示某一行或某几行##替换sed 's###g' oldboy.txtsed 's@@@g' oldboy.txt sed -i 's###g' oldboy.txtsed -i ...

  9. 多线程 线程组 ThreadGroup

    package org.zln.thread; import java.util.Date; /** * Created by sherry on 000024/6/24 22:30. */ publ ...

  10. POJ 3461Oulipo KMP模板

    KMP之所以线性,因为匹配的时候i是不往回走的 我们只用调整j的位置 假设在s中找t 用二元组(i,j)表示s串的[i-j+1,i] 与t串的[1,j]匹配 假设s[i+1]和t[j]匹配上了,就j+ ...