当前位置: 首页 > news >正文

iOS自动化探索(七)自动化测试框架pytest - 测试报告

这里我们单独来看下关于如何生存测试报告

准备测试代码如下:

#coding: utf-8

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.15, pytest-4.1.0, py-1.7.0, pluggy-0.8.0 -- /Users/jackey/Documents/iOS/code/iOS-Auto/MyPyEnv/wda_python/bin/python2.7
cachedir: .pytest_cache
rootdir: /Users/jackey/Documents/iOS/code/iOS-Auto/Agent_Test, inifile:
collected 3 items                                                                                                                        

test_smtpsimple.py::test_step_1 PASSED                                                                                             [ 33%]
test_smtpsimple.py::test_step_2 PASSED                                                                                             [ 66%]
test_smtpsimple.py::test_step_3 PASSED                                                                                             [100%]

---------------------------- generated xml file: /Users/jackey/Documents/iOS/code/iOS-Auto/Agent_Test/log.xml ----------------------------
======================================================== 3 passed in 0.02 seconds ========================================================
(wda_python) bash-3.2$ 

生存的log.xml:

<?xml version="1.0" encoding="utf-8"?><testsuite errors="0" failures="0" name="pytest" skips="0" tests="3" time="0.023"><testcase classname="test_smtpsimple" file="test_smtpsimple.py" line="8" name="test_step_1" time="0.00126314163208"><system-out>输入账号、密码登录
用例步骤1:登录之后其它动作111
</system-out></testcase><testcase classname="test_smtpsimple" file="test_smtpsimple.py" line="11" name="test_step_2" time="0.000802755355835"><system-out>用例步骤2: 不需要登录, 操作222
</system-out></testcase><testcase classname="test_smtpsimple" file="test_smtpsimple.py" line="14" 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.15, pytest-4.1.0, py-1.7.0, pluggy-0.8.0 -- /Users/jackey/Documents/iOS/code/iOS-Auto/MyPyEnv/wda_python/bin/python2.7
cachedir: .pytest_cache
rootdir: /Users/jackey/Documents/iOS/code/iOS-Auto/Agent_Test, inifile:
collected 3 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.7/site-packages/_pytest/resultlog.py:39
  /Users/jackey/Documents/iOS/code/iOS-Auto/MyPyEnv/wda_python/lib/python2.7/site-packages/_pytest/resultlog.py:39: 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=2)

-- Docs: https://docs.pytest.org/en/latest/warnings.html
================================================== 3 passed, 1 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.15, pytest-4.1.0, py-1.7.0, pluggy-0.8.0 -- /Users/jackey/Documents/iOS/code/iOS-Auto/MyPyEnv/wda_python/bin/python2.7
cachedir: .pytest_cache
rootdir: /Users/jackey/Documents/iOS/code/iOS-Auto/Agent_Test, inifile:
collecting ... collected 3 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

=========================== 3 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.15, pytest-4.1.0, py-1.7.0, pluggy-0.8.0 -- /Users/jackey/Documents/iOS/code/iOS-Auto/MyPyEnv/wda_python/bin/python2.7
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.0, html-1.20.0
collected 3 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 ---------------------------
======================================================== 3 passed in 0.03 seconds ========================================================
(wda_python) bash-3.2$ 

生存的log.html用浏览器打开:

 

转载于:https://www.cnblogs.com/zhouxihi/p/10288779.html

相关文章:

  • 2018年台湾人口增加1.8万人 增长率创新低
  • myhome vscode plugins
  • Linux进阶第三天
  • Activiti工作流开发准备(一)
  • oracle如何设置表空间autoextensible自动扩容
  • 面试可能被提问,该如何答复
  • make--变量 条件判断 函数定义及调用
  • 林斌:小米双折叠手机来了 会考虑未来做成量产机发布
  • VRChat简易教程2-创建一个最基本的世界(world)
  • PHP扩展库PEAR被攻击,近半年下载者或被影响
  • Docker: 容器互访的三种方式
  • D. Diverse Garland
  • 火箭主帅德安东尼赞哈登低位防守:他是控球中锋
  • Problem C: [noip2016十连测第五场]travel (构造+贪心)
  • 年终总结,程序员票选最喜欢的编程语言花落谁家?
  • ECS应用管理最佳实践
  • HTML5新特性总结
  • LeetCode29.两数相除 JavaScript
  • LintCode 31. partitionArray 数组划分
  • Linux Process Manage
  • Python代码面试必读 - Data Structures and Algorithms in Python
  • WebSocket使用
  • 机器学习 vs. 深度学习
  • 机器学习中为什么要做归一化normalization
  • 基于 Babel 的 npm 包最小化设置
  • 坑!为什么View.startAnimation不起作用?
  • 前端面试题总结
  • 算法-插入排序
  • 线上 python http server profile 实践
  • 移动端唤起键盘时取消position:fixed定位
  • Linux权限管理(week1_day5)--技术流ken
  • ​软考-高级-系统架构设计师教程(清华第2版)【第1章-绪论-思维导图】​
  • ​香农与信息论三大定律
  • # 深度解析 Socket 与 WebSocket:原理、区别与应用
  • (LeetCode C++)盛最多水的容器
  • (二)Linux——Linux常用指令
  • (十五)Flask覆写wsgi_app函数实现自定义中间件
  • (实战)静默dbca安装创建数据库 --参数说明+举例
  • (转)EXC_BREAKPOINT僵尸错误
  • (转)linux自定义开机启动服务和chkconfig使用方法
  • (轉貼) 蒼井そら挑戰筋肉擂台 (Misc)
  • **Java有哪些悲观锁的实现_乐观锁、悲观锁、Redis分布式锁和Zookeeper分布式锁的实现以及流程原理...
  • .gitignore文件—git忽略文件
  • .net core Swagger 过滤部分Api
  • .Net面试题4
  • .project文件
  • .set 数据导入matlab,设置变量导入选项 - MATLAB setvaropts - MathWorks 中国
  • @RequestBody与@ResponseBody的使用
  • [20180129]bash显示path环境变量.txt
  • [android] 天气app布局练习
  • [BUG] Authentication Error
  • [BZOJ5125]小Q的书架(决策单调性+分治DP+树状数组)
  • [C#] 我的log4net使用手册
  • [C++从入门到精通] 14.虚函数、纯虚函数和虚析构(virtual)
  • [C++打怪升级]--学习总目录