Advertisement
horozov86

worker_testing_with_setUp

Jul 25th, 2023
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.54 KB | None | 0 0
  1. import unittest
  2.  
  3. class WorkerTests(unittest.TestCase):
  4.     def setUp(self):
  5.         self.worker = Worker('Ivan Ivanov', 1000, 10)
  6.        
  7.     def test_initialization(self):
  8.         self.assertEqual('Ivan Ivanov', self.worker.name)
  9.         self.assertEqual(1000, self.worker.salary)
  10.         self.assertEqual(10, self.worker.energy)
  11.         self.assertEqual(0, self.worker.money)
  12.        
  13.     def test_energy_incremented(self):
  14.         worker = Worker('Ivan Ivanov', 1000, 10)
  15.         worker.rest()
  16.         self.assertEqual(worker.energy, 11)
  17.        
  18.     def test_energy_equal_to_zero(self):
  19.         worker = Worker('Ivan Ivanov', 1000, 0)
  20.        
  21.         with self.assertRaises(Exception) as context:
  22.             worker.work()
  23.         self.assertEqual(str(context.exception), 'Not enough energy.')
  24.        
  25.     def test_energy_negative(self):
  26.         worker = Worker('Ivan Ivanov', 1000, -1)
  27.        
  28.         with self.assertRaises(Exception) as context:
  29.             worker.work()
  30.         self.assertEqual(str(context.exception), 'Not enough energy.')
  31.        
  32.     def test_increase_worker_money(self):
  33.         self.worker.work()
  34.         self.assertEqual(self.worker.salary, 1000)
  35.        
  36.     def test_worker_energy_decreased(self):
  37.         self.worker.work()
  38.         self.assertEqual(self.worker.energy, 9)
  39.        
  40.        
  41.     def test_get_info_returns_correct_string(self):
  42.         self.assertEqual(self.worker.get_info(), f'Ivan Ivanov has saved 0 money.')
  43.        
  44.        
  45. if __name__ == '__main__':
  46.     unittest.main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement