python htmltestrunner报告_python使用HTMLTestRunner导出饼图分析报告的方法

本文介绍了如何使用Python的HTMLTestRunner库来创建详细的测试报告。通过一个具体的例子展示了如何编写测试用例,包括成功的登录、用户名不存在和密码错误的场景,并在测试完成后生成HTML格式的测试报告,方便查看和分析测试结果。
摘要由CSDN通过智能技术生成

目录如下:

19123000034159338783029387.png

这里有使用

HTMLTestRunner和 echarts.common.min.js文件[见百度网盘,这里给自己留个记录便于查询]

unit_test.py代码如下:

import unittest

import requests

import time

import os.path

from common import HTMLTestRunner

class TestLogin(unittest.TestCase):

def setUp(self):

# 获取session对象

self.session = requests.session()

# 登录url

self.url = 'http://XXXXXX/oauth/oauth/token'

def test_login_success(self):

data = {

'grant_type': 'password',

'username': 'iu',

'password': '111',

'client_id': 'web',

'client_secret': 'web-secret'

}

r = self.session.post(url=self.url, data=data)

try:

self.assertEqual(r.json()['token_type'])

except AssertionError as e:

print(e)

def test_username_not_exit(self):

data = {

'grant_type': 'password',

'username': '322u',

'password': '8',

'client_id': 'web',

'client_secret': 'web-secret'

}

r = self.session.post(url=self.url, data=data)

try:

self.assertEqual("用户名或密码错误", r.json()["error_description"])

except AssertionError as e:

print(e)

def test_password_error(self):

data = {

'grant_type': 'password',

'username': '2u',

'password': '888ssss888',

'client_id': 'web',

'client_secret': 'web-secret'

}

r = self.session.post(url=self.url, data=data)

try:

self.assertEqual("用户名或密码错误", r.json()["error_description"])

except AssertionError as e:

print(e)

def tearDown(self):

self.session.close()

if __name__ == '__main__':

# unittest.main()

test = unittest.TestSuite()

test.addTest(TestLogin('test_login_success'))

test.addTest(TestLogin('test_username_not_exit'))

test.addTest(TestLogin('test_password_error'))

rq = time.strftime('%Y%m%d%H%M', time.localtime(time.time()))

file_path = os.path.abspath('.') + '\\report\\' + rq + '-result.html'

file_result = open(file_path, 'wb')

runner = HTMLTestRunner.HTMLTestRunner(stream=file_result, title=u'测试报告', description=u'用例执行情况')

runner.run(test)

file_result.close()

运行产生报告

19123000034326122223573897.png查看报告:

19123000034481585305382425.png

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值