代码覆盖率使用指导
TDD介绍
测试驱动开发(Test Driver Developent,TDD),是一种软件开发技术,其核心思想是在编写功能代码之前,先编写测试代码,然后再编码让测试通过,最后重构代码消除重复及优化设计,是编码得到快速反馈。即构造函数参数,为函数的各个分支或异常场景进行测试,验证某些分支是否正常。
开发过程被重构为一个以测试为核心的短周期循环。
注意:代码覆盖不能在windows上跑,只能在linux上跑。
1. 工具安装
sudo apt-get install lcov
sudo apt-get install dos2unix
pip install lxml
pip install selectolax
pip install CppHeaderParser
编译需要在build.gn中加入"--coverage"参数
注意:
先 编译组件so
再 编译测试套
2. 组件so
在build.gn中加入"--coverage"参数
如下例子
在telephony_state_registry组件中加入参数

编译
./build.sh --product-name rk3568 --ccache --build-target tel_state_registry
3. 测试套
在build.gn中加入"--coverage"参数
如下例子
在telephony_state_registry测试套中加入参数

测试用例都加入参数

4. 编译
如下例子
./build.sh --product-name rk3568--ccache --build-target base/telephony/state_registry/test:unittest
5. 运行
运行时加入“-cov coverage”参数
如下例子
run -t UT -tp state_registry -cov coverage
注:跑代码覆盖必须跑部件方式
5.1 本地运行
//linux----->device

5.2 远程运行
//client(linux)----->server(win)----->device
- windows端
//启动核心网络转发的hdc服务
hdc -s 169.254.168.101:8710 -m

- linux端
远程查看能否读到设备
hdc -s 169.254.168.101:8710 list targets
正常能正确读到设备如下

修改user_config.xml配置文件

运行后结果
\test\testfwk\developer_test\local_coverage\code_coverage\html\index.html

更多推荐


所有评论(0)