python自动化测试之连接几组测试包实例

python自动化测试之连接几组测试包实例

本文给出了一个实例,描述了在Python自动化测试中连接多组测试包的方法,供大家参考。具体方法如下:

[En]

In this paper, an example is given to describe the method of connecting several groups of test packages in python automated testing, which is shared for your reference. The specific methods are as follows:

python自动化测试之连接几组测试包实例

具体代码如下:

[En]

The specific code is as follows:

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):
self.cvt = RomanNumeralConverter()

def test_parsing_millenia(self):
self.assertEquals(1000, self.cvt.convert_to_decimal(“M”))

def test_parsing_century(self):
self.assertEquals(100, self.cvt.convert_to_decimal(“C”))

class RomanNumeralConverterCombo(unittest.TestCase):
def setUp(self):
self.cvt = RomanNumeralConverter()

def test_multi_millenia(self):
self.assertEquals(4000, self.cvt.convert_to_decimal(“MMMM”))

def test_add_up(self):
self.assertEquals(2010, self.cvt.convert_to_decimal(“MMX”))

if name == “main“:
suite1 = unittest.TestLoader().loadTestsFromTestCase(RomanNumeralConverterTest)
suite2 = unittest.TestLoader().loadTestsFromTestCase(RomanNumeralConverterCombo)
suite = unittest.TestSuite([suite1, suite2])
unittest.TextTestRunner(verbosity=2).run(suite)

运行结果如下:

[En]

The running results are as follows:

test_parsing_century (main.RomanNumeralConverterTest) … ok
test_parsing_millenia (main.RomanNumeralConverterTest) … ok
test_add_up (main.RomanNumeralConverterCombo) … ok
test_multi_millenia (main.RomanNumeralConverterCombo) … ok

Original: https://www.cnblogs.com/amengduo/p/9586229.html
Author: 刘小子
Title: python自动化测试之连接几组测试包实例

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/7395/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

最近整理资源【免费获取】:   👉 程序员最新必读书单  | 👏 互联网各方向面试题下载 | ✌️计算机核心资源汇总