elena1234

unit test 2 in Python

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