I have made a program which deposits and withdraws some amount into an account. Now I want to unit test this code. The problem is when i try to unit test the code it says: 0 tests in 0.00 secs. I don’t understand this. Here is my code for both the function file and the test file. Please tell me what I am doing wrong.
Function File
balance = 0
def deposit(amount):
balance += amount
def withdraw(amount):
balance -= amount
Test File
import unittest
from BankAccount import deposit, withdraw, balance
class BankATest(unittest.TestCase):
def __init__(self):
pass
def depositTest(self):
result = deposit(100)
self.assertEqual(result, balance(100),None)
def withdrawTest(self):
result = withdraw(100)
self.assertEqual(result, balance(0),None)
I want to check that when I deposit the money using the deposit function, the balance shows the deposited money. Likewise with the withdraw function. Any help or suggestion is appreciated.
OK, so since the last time I posted I have done a few modifications and now it is recognizing the two tests now it’s giving a different kind of error.
Function File
class BankA(object):
def __init__(self,balance):
self.balance = balance
def deposit(self,amount):
self.balance += amount
def withdraw(self,amount):
self.balance -= amount
Test File
import unittest
from BankAccount import BankA
class BankATest(unittest.TestCase):
def setUp(self):
self.newBalance = BankA(0)
def testDeposit(self):
BankA.deposit(100)
self.assertEqual(self.newBalance(100), 100)
def testWithdraw(self):
BankA.withdraw(100)
self.assertEqual(self.newBalance(-100), 0)
if __name__ == '__main__':
unittest.main()
Error: line 21 in testWithdraw.
BankA.withdraw(100)
withdraw() missing one required positional argument: amount