iOS自动化探索(七)自动化测试框架pytest - 测试报告
这里我们单独来看下关于如何生存测试报告
准备测试代码如下:
#coding: utf- import pytest @pytest.fixture()
def login():
print '输入账号、密码登录' def test_step_1(login):
print '用例步骤1:登录之后其它动作111' def test_step_2(): #不需要登录
print '用例步骤2: 不需要登录, 操作222' def test_step_3(login):
print '用例步骤3:登录之后其它动作333'
生成JunitXML 格式的测试报告
JunitXML报告是一种很常用的测试报告,比如可以和Jenkins进行集成,在Jenkins的GUI上显示Pytest的运行结果,非常便利。
运行完case后可以到report路径下去查看相应的xml文件,也可以在PyCharm打开该xml文件查看。
执行命令:
pytest -v test_smtpsimple.py --junitxml=log.xml
运行结果:
(wda_python) bash-3.2$ pytest -v test_smtpsimple.py --junitxml=log.xml
========================================================== test session starts ===========================================================
platform darwin -- Python 2.7., pytest-4.1., py-1.7., pluggy-0.8. -- /Users/jackey/Documents/iOS/code/iOS-Auto/MyPyEnv/wda_python/bin/python2.
cachedir: .pytest_cache
rootdir: /Users/jackey/Documents/iOS/code/iOS-Auto/Agent_Test, inifile:
collected items test_smtpsimple.py::test_step_1 PASSED [ %]
test_smtpsimple.py::test_step_2 PASSED [ %]
test_smtpsimple.py::test_step_3 PASSED [%] ---------------------------- generated xml file: /Users/jackey/Documents/iOS/code/iOS-Auto/Agent_Test/log.xml ----------------------------
======================================================== passed in 0.02 seconds ========================================================
(wda_python) bash-3.2$
生存的log.xml:
<?xml version="1.0" encoding="utf-8"?><testsuite errors="" failures="" name="pytest" skips="" tests="" time="0.023"><testcase classname="test_smtpsimple" file="test_smtpsimple.py" line="" name="test_step_1" time="0.00126314163208"><system-out>输入账号、密码登录
用例步骤1:登录之后其它动作111
</system-out></testcase><testcase classname="test_smtpsimple" file="test_smtpsimple.py" line="" name="test_step_2" time="0.000802755355835"><system-out>用例步骤2: 不需要登录, 操作222
</system-out></testcase><testcase classname="test_smtpsimple" file="test_smtpsimple.py" line="" name="test_step_3" time="0.00115084648132"><system-out>输入账号、密码登录
用例步骤3:登录之后其它动作333
</system-out></testcase></testsuite>
生成result log格式的测试报告
(wda_python) bash-3.2$ pytest -s -v test_smtpsimple.py --resultlog=log.txt
========================================================== test session starts ===========================================================
platform darwin -- Python 2.7., pytest-4.1., py-1.7., pluggy-0.8. -- /Users/jackey/Documents/iOS/code/iOS-Auto/MyPyEnv/wda_python/bin/python2.
cachedir: .pytest_cache
rootdir: /Users/jackey/Documents/iOS/code/iOS-Auto/Agent_Test, inifile:
collected items test_smtpsimple.py::test_step_1 输入账号、密码登录
用例步骤1:登录之后其它动作111
PASSED
test_smtpsimple.py::test_step_2 用例步骤2: 不需要登录, 操作222
PASSED
test_smtpsimple.py::test_step_3 输入账号、密码登录
用例步骤3:登录之后其它动作333
PASSED ============================================================ warnings summary ============================================================
/Users/jackey/Documents/iOS/code/iOS-Auto/MyPyEnv/wda_python/lib/python2./site-packages/_pytest/resultlog.py:
/Users/jackey/Documents/iOS/code/iOS-Auto/MyPyEnv/wda_python/lib/python2./site-packages/_pytest/resultlog.py:: PytestDeprecationWarning: --result-log is deprecated and scheduled for removal in pytest 5.0.
See https://docs.pytest.org/en/latest/deprecations.html#result-log-result-log for more information.
_issue_warning_captured(RESULT_LOG, config.hook, stacklevel=) -- Docs: https://docs.pytest.org/en/latest/warnings.html
================================================== passed, warnings in 0.01 seconds ==================================================
(wda_python) bash-3.2$
现在回提示过期, 生存的Log.txt
. test_smtpsimple.py::test_step_1
. test_smtpsimple.py::test_step_2
. test_smtpsimple.py::test_step_3
可以改成这样:
pytest -s -v test_smtpsimple.py > log.txt
生存的log.txt为
============================= test session starts ==============================
platform darwin -- Python 2.7., pytest-4.1., py-1.7., pluggy-0.8. -- /Users/jackey/Documents/iOS/code/iOS-Auto/MyPyEnv/wda_python/bin/python2.
cachedir: .pytest_cache
rootdir: /Users/jackey/Documents/iOS/code/iOS-Auto/Agent_Test, inifile:
collecting ... collected items test_smtpsimple.py::test_step_1 输入账号、密码登录
用例步骤1:登录之后其它动作111
PASSED
test_smtpsimple.py::test_step_2 用例步骤2: 不需要登录, 操作222
PASSED
test_smtpsimple.py::test_step_3 输入账号、密码登录
用例步骤3:登录之后其它动作333
PASSED =========================== passed in 0.01 seconds ===========================
生成Html格式的测试报告
html格式的测试报告在浏览器观看效果很好,还可以把这些测试报告放在Web服务器上。
首先,需要安装pytest-html插件。
pip install pytest-html
使用指令:
pytest -s -v test_smtpsimple.py --html=log.html
运行结果:
(wda_python) bash-3.2$ pytest -s -v test_smtpsimple.py --html=log.html
========================================================== test session starts ===========================================================
platform darwin -- Python 2.7., pytest-4.1., py-1.7., pluggy-0.8. -- /Users/jackey/Documents/iOS/code/iOS-Auto/MyPyEnv/wda_python/bin/python2.
cachedir: .pytest_cache
metadata: {'Python': '2.7.15', 'Platform': 'Darwin-17.0.0-x86_64-i386-64bit', 'Packages': {'py': '1.7.0', 'pytest': '4.1.0', 'pluggy': '0.8.0'}, 'Plugins': {'html': '1.20.0', 'metadata': '1.8.0'}}
rootdir: /Users/jackey/Documents/iOS/code/iOS-Auto/Agent_Test, inifile:
plugins: metadata-1.8., html-1.20.
collected items test_smtpsimple.py::test_step_1 输入账号、密码登录
用例步骤1:登录之后其它动作111
PASSED
test_smtpsimple.py::test_step_2 用例步骤2: 不需要登录, 操作222
PASSED
test_smtpsimple.py::test_step_3 输入账号、密码登录
用例步骤3:登录之后其它动作333
PASSED --------------------------- generated html file: /Users/jackey/Documents/iOS/code/iOS-Auto/Agent_Test/log.html ---------------------------
======================================================== passed in 0.03 seconds ========================================================
(wda_python) bash-3.2$
生存的log.html用浏览器打开:

iOS自动化探索(七)自动化测试框架pytest - 测试报告的更多相关文章
- iOS自动化探索(四)自动化测试框架pytest - 安装和使用
自动化测试框架 - pytest pytest是Python最流行的单元测试框架之一, 帮助更便捷的编写测试脚本, 并支持多种功能复杂的测试场景, 能用来做app测试也能用作函数测试 官方文档: ht ...
- python3: 自动化测试框架pytest
最近在学习web自动化,所以在这里总结一下pytest框架. 其实pytest 和 unittest 都是自动化测试框架,但是pytest更好用一些,有以下几个优点:1)可以根据标签执行用例:2)?? ...
- iOS自动化探索(六)自动化测试框架pytest - fixtures
Fixture介绍 fixture是pytest特有的功能,它用pytest.fixture标识,定义在函数前面.在编写测试函数的时候,可以将此函数名称做为传入参数,pytest将会以依赖注入方式,将 ...
- iOS自动化探索(五)自动化测试框架pytest - Assert断言的使用
使用assert语句进行断言 pytest允许使用标准的python assert语法,用来校验expectation and value是否一致 代码演示: def func(): def test ...
- Python接口自动化测试框架: pytest+allure+jsonpath+requests+excel实现的接口自动化测试框架(学习成果)
废话 最近在自己学习接口自动化测试,这里也算是完成一个小的成果,欢迎大家交流指出不合适的地方,源码在文末 问题 整体代码结构优化未实现,导致最终测试时间变长,其他工具单接口测试只需要39ms,该框架中 ...
- iOS自动化探索(十)代码覆盖率统计
iOS APP代码覆盖率统计 今年Q3季度领导给加了个任务要做前后端代码覆盖率统计, 鉴于对iOS代码代码比较熟就选择先从iOS端入手,折腾一整天后终于初步把流程跑通了记录如下 覆盖率监测的原理 Xc ...
- iOS自动化探索(一)WebDriverAgent安装
WebDriverAgent FaceBook推出的一款iOS移动测试框架, 支持真机和模拟器, 同时支持USB, 官方是这样介绍的: https://github.com/facebook/WebD ...
- iOS自动化探索(九)使用Jenkins自动化打包并发布iOS App
继前一篇: Mac环境下安装Jenkins Jenkins安装好后, 我们试着创建一个iOS自动打包并发布的任务 iOS App构建必须在MAC上面使用xcode进行,所以我们要安装下xcode集成插 ...
- iOS自动化探索(三)WebDriverAgent Python Client
之前我们在终端试着调用过WDA API, 今天我们在看一个Python封装的api库 https://github.com/openatx/facebook-wda 安装方式(一): pip inst ...
随机推荐
- javaScript动画2 scroll家族
offsetWidth和offsetHight (检测盒子自身宽高+padding+border) 这两个属性,他们绑定在了所有的节点元素上.获取之后,只要调用这两个属性,我们就能够获取元素节点的宽和 ...
- java5引入的并发编程库
java5之后引入了java.util.concurrent包,专门用于解决java多线程问题. AtomicInteger用于解决原子性操作(i++,i--的问题): AtomicInteger ...
- pigeon 介绍
https://github.com/dianping/pigeon Pigeon开发指南 Pigeon是一个分布式服务通信框架(RPC),在美团点评内部广泛使用,是美团点评最基础的底层框架之一. 主 ...
- [Deep Learning]学习资料积累
1. ufldl教程√ Andrew Ng的教程,matlab代码. 2. Neural Network and Deep Learning√: 一本未写完的书,非常细致,对基础的概念比如cross ...
- Maven 中央仓库搭建
Maven中央仓库搭建 搭建系统:Linux Centos 7.4 x64 安装环境:JDK1.8.maven3.5.4.nexus-3.13 下载:nexus-3.13.0-01-unix.tar. ...
- 一个url加载的全过程
最近在进行前端面试方面的一些准备,遇到了一个经典前端问题,一个url从输入到页面加载中间到底发生了什么,以前也认真想过这个问题,但是当时回答的都不全面,现在来好好总结一下: 总体来说分为以下六个步骤: ...
- elasticsearch 5.5.1 head插件安装
5.5.1版本与之前版本有很大不同. 1. 下载插件 git clone git://github.com/mobz/elasticsearch-head.git 2. 编译 cd elasticse ...
- 20145321 《Java程序设计》第7周学习总结
20145321 <Java程序设计>第7周学习总结 教材学习内容总结 第十三章 时间与日期 13.1 认识时间与日期 1.格林威治时间(GMT) 观察太阳得来 2.世界时(UT) 3.国 ...
- js事件委托篇(附js一般写法和js、jq事件委托写法)
参考: jQuery代码优化:事件委托篇 使用该技术能让你避免对特定的每个节点添加事件监听器:相反,事件监听器被添加在他们的父元素上,事件监听器会分析从子元素上冒泡上来的事件,并找到是哪个子元素事件. ...
- mybatis关联配置(一对多配置)
敲代码也有不少日子了,今天碰到个需求,就是定时器生成一张表,但是这个表的某些数据是从另外两张表中拿到的,定外两张表又是一对多的关系,想着咋在一个接口就能敲出来,大概结构如下 然后需要a表的数据(比如张 ...