python自动化测试之setUp与tearDown实例
作者:shichen2014 时间:2021-07-01 13:35:13
本文实例讲述了python自动化测试之setUp与tearDown的用法,分享给大家供大家参考。具体如下:
实例代码如下:
class RomanNumeralConverter(object):
def __init__(self):
self.digit_map = {"M":1000, "D":500, "C":100, "L":50, "X":10,
"V":5, "I":1}
def convert_to_decimal(self, roman_numeral):
val = 0
for char in roman_numeral:
val += self.digit_map[char]
return val
import unittest
class RomanNumeralConverterTest(unittest.TestCase):
def setUp(self):
print "Create a new RomanNumeralConverterTest....."
self.cvt = RomanNumeralConverter()
def tearDown(self):
print "Destroying a RomanNumeralConverterTest...."
self.cvt = None
def test_parsing_millenia(self):
self.assertEquals(1000, self.cvt.convert_to_decimal("M"))
if __name__ == "__main__":
unittest.main()
输出结果如下:
Create a new RomanNumeralConverterTest.....
Destroying a RomanNumeralConverterTest....
.
----------------------------------------------------------------------
Ran 1 test in 0.016s
OK
注:setUp和tearDown在每个测试方法运行时被调用
标签:python
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Python+OpenCV数字图像处理之ROI区域的提取
2021-01-17 18:54:43
![](https://img.aspxhome.com/file/2023/8/81848_0s.jpg)
Python判断变量是否已经定义的方法
2023-08-01 07:14:01
用ASP在线创建Word与Excel文档
2008-07-20 19:17:00
PyQt5根据控件Id获取控件对象的方法
2023-02-13 15:22:50
MySQL UPDATE delete 语句的速度
2008-03-12 12:22:00
matplotlib设置legend图例代码示例
2023-04-18 13:20:12
![](https://img.aspxhome.com/file/2023/5/78515_0s.jpg)
css学习笔记:为什么在IE6下图片会往下掉一行
2009-06-19 12:50:00
![](https://img.aspxhome.com/file/UploadPic/20099/25/2009925225543206s.jpg)
MySQL优化之数据类型的使用
2009-03-16 17:12:00
安装PHP遇到“无法载入mysql扩展”解决方法
2007-06-15 15:04:00
对Python Pexpect 模块的使用说明详解
2022-10-24 02:14:09
asp动态页面防采集的新方法
2011-02-26 10:44:00
Python 动态导入对象,importlib.import_module()的使用方法
2023-01-24 01:48:47
python得到windows自启动列表的方法
2023-12-18 14:49:13
Python之ascii转中文的实现
2023-08-24 19:39:12
![](https://img.aspxhome.com/file/2023/0/62600_0s.png)
Python实现HTTP协议下的文件下载方法总结
2023-04-29 20:01:36
[翻译]网页设计中的模式窗口
2009-05-29 18:00:00
![](https://img.aspxhome.com/file/UploadPic/20095/29/376600_124350365243zv-44s.jpg)
Python Tkinter基础控件用法
2023-04-11 18:35:14
![](https://img.aspxhome.com/file/2023/5/107545_0s.png)
python基本语法练习实例
2021-02-25 06:50:07
python中pyplot直方图的绘制方式
2023-11-20 07:58:17
![](https://img.aspxhome.com/file/2023/1/63541_0s.png)
查询字符串中包含特殊字符的问题
2009-01-09 13:13:00