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的更多相关文章
随机推荐
- git 本地项目推到远程仓库
…or create a new repository on the command line echo "# blog" >> README.mdgit initgi ...
- JAVA之锁-volatile
锁是JAVA多线程关键,也是面试中必问的, 在此好好总结一下. (先要从进程和线程说起,此处先欠下,回头专门说一下操作系统是怎么管理进程和线程的) 说到多线程就要说说JAVA的内存模型:图片来自于网络 ...
- idea使用记录
1.在工具栏添加工具
- 模拟赛20181015 Uva1078 bfs+四维dp
题意:一张网格图,多组数据,输入n,m,sx,sy,tx,ty大小,起终点 接下来共有2n-1行,奇数行有m-1个数,表示横向的边权,偶数行有m个数,表示纵向的边权 样例输入: 4 4 1 1 ...
- 扩展欧几里得(exgcd)与同余详解
exgcd入门以及同余基础 gcd,欧几里得的智慧结晶,信息竞赛的重要算法,数论的...(编不下去了 讲exgcd之前,我们先普及一下同余的性质: 若,那么 若,,且p1,p2互质, 有了这三个式子, ...
- Spring rabbitMq 中 correlationId或CorrelationIdString 消费者获取为null的问题
问题 在用Spring boot 的 spring-boot-starter-amqp 快速启动 rabbitMq 是遇到了个坑 消费者端获取不到:correlationId或Correlatio ...
- 原生JS实现简易评论更新功能
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- golang _下划线占位符代替需要释放的资源的问题
golang中_有两种作用,一种用在import中,比如这样 import _ "github.com/go-sql-driver/mysql" 表示并不需要导入整个包,只是执行这 ...
- list不是模板
vector和list在命名空间std里,还需要添加声明 using namespace std;
- day 21 - 1 包,异常处理
创建目录代码 1. 无论是 import 形式还是 from...import 形式,凡是在导入语句中(而不是在使用时)遇到带点的,都要第一时间提高警觉:这是关于包才有的导入语法2. 包是目录级的(文 ...