如何使用Python Unitest和Init方法运行多个测试用例?
我试图开发计算器到Unitest 我尝试使用Python Unitest和Init方法运行测试用例。我总是遇到此错误。
错误:
attributeError:'testingClass'对象没有属性'runtest'。您的意思是:“子测验”?
我尝试使用重命名方法名称runtest来解决此错误。但这仅适用于一个测试用例。我想运行多个测试用例。所以我想帮助您。如何运行多个测试用例?
这是我的calculator_test.py file
###这是phython单元测试模块
import untest
想测试。因此,我们需要将其导入
导入carculator_steps作为calculatorClass
类TestingClass(unittest.testcase):
"""
The basic class that inherits unittest.TestCase
"""
def __init__(self, *args, **kwargs):
super(TestingClass, self).__init__()
self.calculator = CalculatorClass.Calculator()
#requirment 1:验证计算器仅接受整数。
def runTest(self):
with self.assertRaises(Exception):
self.calculator.addNumbers('5.66,3.44')
#requirment 2:验证计算器不接受非数字值。
def test_NonNumeric(self):
with self.assertRaises(Exception):
self.calculator.addNumbers('5,6,e')
我的calculator_steps.py文件
类计算器:
def addNumbers(self,numberlist):
total = ""
return total
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是如何运行单元测试的文档, ,,,,
另外,请使用
测试_
前缀启动测试功能,然后Unittest才能知道这是一个测试。Here is the docs for how to run unit tests, https://docs.python.org/3/library/unittest.html#command-line-interface ,
Also please start the test function with
test_
prefix only then unittest will get to know it is a test.