Advertisement
elena1234

unit test in Python

Feb 14th, 2022 (edited)
676
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.83 KB | None | 0 0
  1. import unittest
  2. import main
  3.  
  4. class TestMain(unittest.TestCase):
  5.     def setUp(self):
  6.         print("About to test a function")
  7.        
  8.     def test_sum(self):
  9.         test_param = 10
  10.         result = main.sum(test_param)
  11.         self.assertEqual(result, 15)
  12.        
  13.     def test_sum2(self):
  14.         test_param = "abc"
  15.         result = main.sum(test_param)
  16.         self.assertIsInstance(result, ValueError)
  17.    
  18.     def test_sum3(self):
  19.         test_param = None
  20.         result = main.sum(test_param)
  21.         self.assertIsInstance(result, TypeError)
  22.    
  23.      def tearDown(self):
  24.         print("cleaning up")
  25.        
  26.  
  27. if __name__ == "__main__":
  28.    unittest.main()
  29.  
  30.  
  31. # testing in main.py
  32. # def sum(num):
  33.     #try:
  34.      #return int(num) + 5
  35.  
  36.     #except (ValueError, TypeError) as error:
  37.         #return error
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement