当前位置:Gxlcms > Python > python自动化测试之从命令行运行测试用例withverbosity

python自动化测试之从命令行运行测试用例withverbosity

时间:2021-07-01 10:21:17 帮助过:191人阅读

本文实例讲述了python自动化测试之从命令行运行测试用例with verbosity,分享给大家供大家参考。具体如下:

实例文件recipe3.py如下:

  1. class RomanNumeralConverter(object):
  2. def __init__(self, roman_numeral):
  3. self.roman_numeral = roman_numeral
  4. self.digit_map = {"M":1000, "D":500, "C":100, "L":50, "X":10,
  5. "V":5, "I":1}
  6. def convert_to_decimal(self):
  7. val = 0
  8. for char in self.roman_numeral:
  9. val += self.digit_map[char]
  10. return val
  11. import unittest
  12. class RomanNumeralConverterTest(unittest.TestCase):
  13. def test_parsing_millenia(self):
  14. value = RomanNumeralConverter("M")
  15. self.assertEquals(1000, value.convert_to_decimal())
  16. def test_parsing_century(self):
  17. '''THIS is a error test case'''
  18. value = RomanNumeralConverter("C")
  19. self.assertEquals(10, value.convert_to_decimal())
  20. if __name__ == "__main__":
  21. suite = unittest.TestLoader().loadTestsFromTestCase(RomanNumeralConverterTest)
  22. unittest.TextTestRunner(verbosity=2).run(suite)

运行结果如下图所示:

这就是测试用例失败的样子。

希望本文所述对大家的Python程序设计有所帮助

人气教程排行