浏览 3009 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
|
|
---|---|
作者 | 正文 |
发表时间:2010-03-02
"""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() 声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |
发表时间:2010-03-11
where is the TestSuite?
|
|
返回顶楼 | |