python 面向对象入门 - 之 单元测试
来源:互联网 发布:怎样成为淘宝卖家 编辑:程序博客网 时间:2024/05/17 04:14
详细代码见附件
- """Unit test for odbchelper.py
- This program is part of "Dive Into Python", a free Python book for
- experienced programmers. Visit http://diveintopython.org/ for the
- latest version.
- """
- #加载单元测试模块
- import unittest
- #加载 你的编写的模块
- import odbchelper
- #测试中包括:
- #1.正面测试
- #2.负面测试
- #3.完备性测试:A状态->B状态 ->A状态
- #正面测试
- class GoodInput(unittest.TestCase): #这里要继承 unittest.TestCase
- #编写测试用例,以test 开头
- def testBlank(self):
- """buildConnectionString handles empty dictionary"""
- self.assertEqual("", odbchelper.buildConnectionString({}))
- def testKnownValue(self):
- """buildConnectionString returns known result with known input"""
- params = {"server":"mpilgrim", "database":"master", "uid":"sa", "pwd":"secret"}
- knownItems = params.items()
- knownItems.sort()
- knownString = repr(knownItems)
- result = odbchelper.buildConnectionString(params)
- resultItems = [tuple(e.split("=")) for e in result.split(";")]
- resultItems.sort()
- resultString = repr(resultItems)
- self.assertEqual(knownString, resultString)
- #负面测试
- class BadInput(unittest.TestCase):
- def testString(self):
- """buildConnectionString should fail with string input"""
- self.assertRaises(AttributeError, odbchelper.buildConnectionString, "")
- def testList(self):
- """buildConnectionString should fail with list input"""
- self.assertRaises(AttributeError, odbchelper.buildConnectionString, [])
- def testTuple(self):
- """buildConnectionString should fail with tuple input"""
- self.assertRaises(AttributeError, odbchelper.buildConnectionString, ())
- if __name__ == "__main__":
- unittest.main()
- python 面向对象入门 - 之 单元测试
- python 面向对象入门 - 之 正则表达式
- python 面向对象入门 - 之 Web Service
- PYTHON面向对象入门
- python面向对象入门
- python 之面向对象
- python之面向对象
- Python之面向对象
- python入门(二十七):面向对象之封装
- python入门(二十八):面向对象之继承
- python面向对象入门之奇怪的静态变量
- python入门3-面向对象
- Python之OO 面向对象
- python学习之--面向对象
- Python面向对象之继承
- Python学习之面向对象
- Python 教程之面向对象
- python之面向对象编程
- error C2065: “IDD_DIALOG1”: 未声明的标识符 .
- 句柄
- C#中数据库的更新和删除记录的两种实现方式
- 2012-02-18 09:55 android信息提示框与对话框 转载的,看着方便
- IE 浏览器的创新
- python 面向对象入门 - 之 单元测试
- paip.activex控件在WEB中使用流程与工具
- JAVA实现Excel导入/导出【转】
- WPF---ListView添加窗格线
- Xcode 4 常用快捷键
- RTMP协议详解(转)
- python中读写文件及中文编码处理方法
- Android 对话框基本应用详细教程
- 如何计算某天是星期几