高颜值测试报告-xTestRunner

pip install XTestRunner
# test_unit.py
import unittest
from XTestRunner import HTMLTestRunner class TestDemo(unittest.TestCase):
"""测试用例说明""" def test_success(self):
"""执行成功"""
self.assertEqual(2 + 3, 5) @unittest.skip("skip case")
def test_skip(self):
"""跳过用例"""
pass def test_fail(self):
"""失败用例"""
self.assertEqual(5, 6) def test_error(self):
"""错误用例"""
self.assertEqual(a, 6) if __name__ == '__main__':
suit = unittest.TestSuite()
suit.addTests([
TestDemo("test_success"),
TestDemo("test_skip"),
TestDemo("test_fail"),
TestDemo("test_error")
]) with(open('./result.html', 'wb')) as fp:
runner = HTMLTestRunner(
stream=fp,
title='<project name>test report',
description='describe: ... ',
language='en',
)
runner.run(
testlist=suit,
rerun=2,
save_last_run=False
)

HtmlTestRunner 类说明

  • stream : 指定报告的路径
  • title : 报告的标题
  • description : 报告的描述,支持 str , list 俩种类型
  • language : 支持中文 zh-CN,默认 en

run() 方法说明

  • testlost : 运行的测试套件
  • return :重跑次数
  • save_last_run : 是否保存最后一个重跑结果

运行测试

python test_unit.py
接口测试
import requests
import unittest
from XTestRunner import HTMLTestRunner class YouTest(unittest.TestCase): def test_get(self):
"""测试get接口 """
r = requests.get("https://httpbin.org/get", params={"key":"value"})
print(r.json()) def test_post(self):
"""测试post接口 """
r = requests.post("https://httpbin.org/post", data={"key":"value"})
print(r.json()) def test_put(self):
"""测试put接口 """
r = requests.put("https://httpbin.org/put", data={"key":"value"})
print(r.json()) def test_delete(self):
"""测试delete接口 """
r = requests.delete("https://httpbin.org/delete", data={"key":"value"})
print(r.json()) if __name__ == '__main__':
report = "./reports/api_result.html"
with(open(report, 'wb')) as fp:
unittest.main(testRunner=HTMLTestRunner(
stream=fp,
title='Seldom自动化测试报告',
description=['类型:API', '地址:https://httpbin.org/', '执行人:xx']
))
支持黑白名单

可以通过黑白名单选择要执行(或跳过)的用例

支持黑白名单

  • 白名单:whitelist=["base"]只有使用@label('base')装饰的用例执行
  • 黑名单:blacklist=['slow']只有使用@label('slow')装饰的用例不被执行

测试用例

import unittest
from XTestRunner import label
from XTestRunner import HTMLTestRunner class LabelTest(unittest.TestCase): @label("base")
def test_label_base(self):
self.assertEqual(1+1, 2) @label("slow")
def test_label_slow(self):
self.assertEqual(1, 2) def test_no_label(self):
self.assertEqual(2+3, 5) if __name__ == '__main__':
report = './reports/label_result.html'
with(open(report, 'wb')) as fp:
unittest.main(testRunner=HTMLTestRunner(
stream=fp,
title='<project name>test report',
description='describe: ... ',
whitelist=["base"], # 设置白名单
# blacklist=["slow"], # 设置黑名单
))

xTestRunner的更多相关文章

  1. 高颜值测试报告- XTestRunner

    Modern style test report based on unittest framework. 基于unittest框架现代风格测试报告. 特点 漂亮测试报告让你更愿意编写测试. 支持单元 ...

随机推荐

  1. 字符串转换整数(atoi)(4.3leetcode每日打卡)

    一堆if不及python的一个正则表达式系列 请你来实现一个 atoi 函数,使其能将字符串转换成整数. 首先,该函数会根据需要丢弃无用的开头空格字符,直到寻找到第一个非空格的字符为止.接下来的转化规 ...

  2. go基础-方法

    概述 方法是面向对象编程 (OOP) 的一个特性,在 C++/Java 语言中方法是类函数,go做为函数式编程语言,通过特有技能支持相似的功能,所以说go也支持面向对象编程特性. go 方法本质也是函 ...

  3. Ubuntu 18.04替换默认软件源

    安装Ubuntu 18.04后,默认源在国外,可以替换为国内的源以提升访问速度 参考https://mirrors.ustc.edu.cn/repogen/ sudo vi /etc/apt/sour ...

  4. 【scipy 基础】--统计分布

    scipy.stats子模块包含大量的概率分布.汇总和频率统计.相关函数和统计测试.掩蔽统计.核密度估计.准蒙特卡罗功能等等. 这个子模块可以帮助我们描述和分析数据,进行假设检验和拟合统计模型等. 1 ...

  5. 什么是cursor?怎么使用cursor?

    Cursor 在Android查询数据时就是通过Cursor类来实现的.当我们使用SQLiteDatabase.query()方法时,就会得到Cursor对象,Cursor所指向的就是每一条数据. 举 ...

  6. Go语言数组与切片学习总结

    一.数组 数组的定义:相同类型的数据集合 go语言中数组的索引从0开始 没有赋值的数值型数组,默认值为0 数组一旦被创建,它的大小就是不可改变的 (1)声明数组与打印 var 变量名 [大小]变量类型 ...

  7. P8594 「KDOI-02」一个仇的复 题解

    我会组合数! 首先发现同一列只有被不同的横块填或被一个相同的竖块填,且用竖块填完1列之后,会分成两个封闭的长方形,而长方形内部则用横块来填充. 先考虑一个子问题,某个 \(2 \times n\) 长 ...

  8. 组合式api-侦听器watch的语法

    和vue2对比,也是语法上稍有不同. 监听单个数据对象 <script setup> import {ref, watch} from "vue"; const cou ...

  9. lottie 动画在 vue 中的使用

    前言 最近我所负责的项目中,我采用了动画效果,并开始使用 gif 来实现.然而,在实践过程中,我发现 gif 格式的动画在 git 中出现了明显的锯齿感,这让我非常困扰.为了追求更完美的表现效果,我最 ...

  10. NetSuite Tips —— 发送邮件未被接收或被退回

    Background: NS 发送的邮件过于频繁被邮箱系统识别为垃圾邮件,被拒收或被拦截 Solution: 添加以下邮箱地址到白名单 system@sent-via.netsuite.com nlm ...