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 ...
随机推荐
- MySQL中锁详解(行锁、表锁、页锁、悲观锁、乐观锁等)
悲观锁: 顾名思义,很悲观,就是每次拿数据的时候都认为别的线程会修改数据,所以在每次拿的时候都会给数据上锁.上锁之后,当别的线程想要拿数据时,就会阻塞,直到给数据上锁的线程将事务提交或者回滚.传统的关 ...
- intellij-idea打包Scala代码在spark中运行
.创建好Maven项目之后(记得添加Scala框架到该项目),修改pom.xml文件,添加如下内容: <properties> <spark.version></spar ...
- zookeeper No route to host
2017-10-12 07:25:59,270 [myid:1] - WARN [QuorumPeer[myid=1]/0:0:0:0:0:0:0:0:2181:QuorumCnxManager@36 ...
- RESTful风格与RESTful Api
REST(representational state transfer)(表述性状态转移),词汇解析: 1.representational 表述性:指资源以用各种形式来表述,包括 XML.JSON ...
- 20144303 《Java程序设计》第五周学习总结
20144303 <Java程序设计>第五周学习总结 教材学习内容总结 第八章 异常处理 异常就是程序在运行时出现不正常情况,异常的由来是因为Java把出现的问题封装成了对象,换句话说Ja ...
- Java对map进行排序并生成序号
最近做的项目有这样一个需求:要求对map中的值进行排序并生成序号.如果值相等则序号不变:如果不相等序号为该数数值在所有元素中的索引.如下表所示: Key(String) Value(Float) Id ...
- Vue.js项目部署在Tomcat服务器上
1.在本地的Vue框架中 执行npm run build 将我们的项目打包到dist 文件夹中 2.在服务器上的Tomcat的 webapps文件夹下,新建一个文件夹如:frontvue 3.启动t ...
- JSon数据类型&使用基础
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- 08_MySQL DQL_SQL99标准中的多表查询(内连接)
# sql99语法/*语法: select 查询列表 from 表1 别名 [连接类型] join 表2 别名 on 连接条件 [where 筛选条件] [group by 分组] [having 分 ...
- 关于ckeditor 之 上传功能
度了很多文章,看了很多关于ckeditor配置上传功能的文章,没一个写得清楚的, 就是简单的根目录下.config.js 增加 config.filebrowserUploadUrl="/a ...