接口测试的本质 就是测试类里面的函数、

单元测试的本质  测试函数 代码级别

单元测试框架 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的更多相关文章

随机推荐

  1. 七.django模型系统(一)

    Ⅰ.django的ORM 1.含义 对象关系映射(英语:(Object Relational Mapping,简称ORM,或O/RM,或O/R mapping),是一种程序技术,用于实现面向对象编程语 ...

  2. django-crontab实现定时任务

    django-crontab实现服务端的定时任务 安装 pip install django-crontab 在Django项目中使用 settings.py INSTALLED_APPS = ( ' ...

  3. 优雅的使用git

    1.当我们成功安装git后,首先要做的就是配置我们的用户名以及邮箱: git config --global user.name "xxx" git config --global ...

  4. day22 栈 , 队列 , 约束和反射

    #!/usr/bin/env python# -*- coding:utf-8 -*- # 1.请使用面向对象实现栈(后进先出)"""class Account: def ...

  5. 一文说尽MySQL事务及ACID特性的实现原理

    MySQL 事务基础概念 事务(Transaction)是访问和更新数据库的程序执行单元:事务中可能包含一个或多个 sql 语句,这些语句要么都执行,要么都不执行.作为一个关系型数据库,MySQL 支 ...

  6. 查看提交历史(git log)

    git log 命令 在完成了几次提交,或者克隆了一个已有提交历史的仓库后,要查看历史提交记录,可以通过git log命令来实现. $ git log commit 0becea8e1966df258 ...

  7. list不是模板

    vector和list在命名空间std里,还需要添加声明 using namespace std;

  8. PLSQL Developer导入dmp文件,一闪而过

    在导入数据的时候,一闪而过,也没有任何报错信息. 在环境变量里添加ORACLE_HOME=D:\app\product\11.2.0\dbhome_1就行,此路径是指oracle安装路径.我是用这种方 ...

  9. wireshark 抓包过滤器使用

    目录 wireshark 抓包过滤器 一.抓包过滤器 二.显示过滤器 整理自陈鑫杰老师的wireshark教程课 wireshark 抓包过滤器 过滤器分为抓包过滤器和显示过滤器,抓包过滤器会将不满足 ...

  10. pythonのdjango 信号

    一.内置信号 Django中提供了“信号调度”,用于在框架执行操作时解耦.通俗来讲,就是一些动作发生的时候,信号允许特定的发送者去提醒一些接受者. Model signals pre_init # d ...