-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest2.py
40 lines (32 loc) · 1.21 KB
/
test2.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#unittest is used to test our code
#very important toavoid all types of errors and handle them
import unittest
import main
class TestMain(unittest.TestCase):
def setUp(self): #runs before every test function
print("About to test a function")
def test_do_stuff(self):
"""This is a test""" #you can also use docstrings
test_param = 10
result = main.do_stuff(test_param)
self.assertEqual(result, 15)
def test_do_stuff2(self):
test_param = 'savfhab'
result = main.do_stuff(test_param)
self.assertIsInstance(result, ValueError)
def test_do_stuff3(self):
test_param = None
result = main.do_stuff(test_param)
self.assertTrue(result, 'please enter number')
def test_do_stuff4(self):
test_param = ''
result = main.do_stuff(test_param)
self.assertTrue(result, 'please enter number')
def test_do_stuff5(self):
test_param = 0
result = main.do_stuff(test_param)
self.assertTrue(result, 'please enter number other than 0')
def tearDown(self): #also runs after every test
print("cleaning up some code")
if __name__ == '__main__':
unittest.main()