10_27_unittest
接口测试的本质 就是测试类里面的函数、
单元测试的本质 测试函数 代码级别
单元测试框架 unittest 接口 pytest web
功能测试:
1、写用例 ----> TestCase
2、执行用例 ----> 1:TestSuite 存储用例 2:TestLoader ----> 找用例 ,加载用例,存到1的testSuite 跑特定的用例
3、对比结果----> 断言 Asser
4、出具测试报告----> TextTestRunner
#编写测试用例
#1:一个用例就是一个函数 不能传参 只有self关键字
#所有的用例(所有的函数 都是test开头 test_)
#输出结果 根据ASCII编码排序
import unittest
from GYP_test.math import MathMethod #测试的目标
class TestMathMethon(unittest.TestCase):#继承了unittest里面的TestCase 专门来写用例
#编写测试用例
#1:一个用例就是一个函数 不能传参 只有self关键字
#所有的用例(所有的函数 都是test开头 test_)
def test_add_two_positive(self):
res = MathMethod(1,1).add()
print('1+1的结果值是:',res)
def test_add_two_zero(self):
res = MathMethod(0, 0).add()
print('0+0的结果值是:', res)
def test_add_two_fushu(self):
res = MathMethod(-1, -2).add()
print('-1+-2的结果值是:',res)
#输出结果 根据ASCII编码排序
if __name__ == '__main__':
unittest.main()
执行特定的用例如下:

import unittest
from GYP_test.math import MathMethod #测试的目标
class TestMathMethon(unittest.TestCase):#继承了unittest里面的TestCase 专门来写用例
#编写测试用例
#1:一个用例就是一个函数 不能传参 只有self关键字
#所有的用例(所有的函数 都是test开头 test_)
def test_add_two_positive(self):
res = MathMethod(1,1).add()
print('1+1的结果值是:',res)
def test_add_two_zero(self):
res = MathMethod(0, 0).add()
print('0+0的结果值是:', res)
def test_add_two_fushu(self):
res = MathMethod(-1, -2).add()
print('-1+-2的结果值是:',res)
#输出结果 根据ASCII编码排序
if __name__ == '__main__':
unittest.main()
import unittest
from GYP_test.class_01 import TestMathMethon suite= unittest.TestSuite()#存储用例
#方法一:
#只执行一条 两个数相加
# suite.addTest(TestMathMethon('test_add_two_zero'))
# suite.addTest(TestMathMethon('test_add_two_positive')) #方法二 TestLoader
loader = unittest.TestLoader()#加载器
suite.addTest(loader.loadTestsFromTestCase(TestMathMethon))
loader.loadTestsFromModule()#从模块中加载 具体的模块 类名是找不到的 #执行
runner= unittest.TextTestRunner()
runner.run(suite)
10_27_unittest的更多相关文章
随机推荐
- (二叉树 递归) leetcode 145. Binary Tree Postorder Traversal
Given a binary tree, return the postorder traversal of its nodes' values. Example: Input: [1,null,2, ...
- python1--计算机原理 操作系统 进制 内存分布
本周内容 '''第一天: 计算机原理 操作系统 第二天: 编程语言 python入门:环境 - 编辑器 变量 基本数据类型 '''``` ## 学习方法 ```python'''鸡汤 - 干货 ...
- mac-redis安装与使用
安装: brew install redis --------------- 使用: 启动redis-server: sudo redis-server 连接:./redis-cli -h 127.0 ...
- mvn test报错
1 Scenarios (1 passed) 4 Steps (4 passed) 0m11.846s [INFO] Tests run: 1, Failures: 0, Errors: 0, Ski ...
- 开源顶级持久层框架——mybatis(ibatis)——day01
mybatis-day01 1.对原生态jdbc程序中的问题总结 1.1环境 java环境:jdk eclipse:indigo ...
- JS 获取图片的base64编码
获取图片的base64编码 <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> ...
- echarts笔记
常见问题: 1.x轴和y轴type同时为category时不可行 只能改变方式显示,返回不同名称,如加上百分比显示 formatter:"value%"; var waterLev ...
- 零基础开发一款微信小程序商城
零基础开发一款微信小程序商城 一个朋友问我能不能帮忙做个商城?我一个完整网页都写不出的 菜鸟程序员,我该怎么拒绝呢?好吧,看在小程序这么火的形势下,我还是答应了!找了个开源项目,差不多花了三天时间搞定 ...
- python2编码问题
前言:python3解决了编码的问题,但python2还存在很多编码问题,用P2写爬虫爬了网页,解析时常有不同字符混着编码,导致解码问题成为爬虫程序员的噩梦... 但咱们要用robot framewo ...
- Burp插件开发——环境配置
最近打算开发个Burp插件,从网上各种地找资料学习.第一步就应该是环境配置,请见下文. (其实最重要的前提是你已经安装了Burp,否则下面的所有内容都是无稽之谈了. https://pan.baidu ...