'I'm struggling to create a unit test, if someone could please have a look on my code to figure out the possible issue:
The code below is supposed to simulate a ATM, I have to create 5 unit tests for the code, and to be honest I have no idea why it is not working! :( It should show on the Terminal that ran 5 tests in x s, however it keeps saying that Ran 0 tests and OK. Should I import a library? Any suggestion?
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
Solution 1:[1]
You should name your test methods with test prefix so that the test runner can identify test methods. See here for example.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | annonymous |
