我正在努力创建一个单元测试,如果有人可以看看我的代码以找出可能的问题:



下面的代码应该模拟ATM,我必须为代码创建5个单元测试,老实说,我不知道为什么它不工作!:(它应该显示在x s内运行了5个测试的终端上,但它一直说运行了0个测试并正常。我应该导入一个库吗?有什么建议吗?

import unittest
def withdraw(wdra):
balanace_account = 100
if wdra < balanace_account:
balanace_account -= wdra
return balanace_account

class AtmTest(unittest.TestCase):
def correct_amount(self):
expected = 29.50 #withdraw de 70.50
result = withdraw(70.5)
self.assertEqual(expected,result)
def invalid_error(self):
expected = 1
result = withdraw(1/0)
self.assertEqual(expected, result)
def incorrect_amount(self):
expected = 50.00
result = withdraw(60)
self.assertEqual(expected,result)
def greater_withdraw(self):
expected = -10
result = withdraw(110)
self.assertEqual(expected,result)
def invalid_data_type(selfS):
expected = 100
result = withdraw('0')
self.assertEqual(expected, result)

if __name__ == '__main__':
unittest.main()

pass

您应该使用test前缀来命名测试方法,以便测试运行程序能够识别测试方法。例如,请参见此处。

最新更新