class TestingEmployee(unittest.TestCase): i = 1 @classmethod def setUpClass(cls): print("setUpClass -> Appears at the top\n") @classmethod def tearDownClass(cls): print("tearDownClass -> Appears at the bottom\n") def setUp(self): self.emp_1 = Employee('Pareksha', 'Manchanda', 100) self.emp_2 = Employee('Bhaiya', 'Manchanda', 200) def tearDown(self): print('Test {} passed'.format(TestingEmployee.i)) TestingEmployee.i += 1 def test_fullname(self): print("Running test on fullname method") self.assertEqual(self.emp_1.full_name, 'Pareksha Manchanda') self.assertEqual(self.emp_2.full_name, 'Bhaiya Manchanda') def test_email(self): print('Running test on email method') self.assertEqual(self.emp_1.email, '*****@*****.**') self.assertEqual(self.emp_2.email, '*****@*****.**') def test_raise(self): print('Running test on raise amount method') self.assertEqual(self.emp_1.apply_raise(), 105) self.assertEqual(self.emp_2.apply_raise(), 210)
class TestEmployee(unittest.TestCase): @classmethod def setUpClass(cls): print('setupClass') @classmethod def tearDownClass(cls): print('teardownClass') def setUp(self): print('setUp') self.emp_1 = Employee('Corey', 'Schafer', 50000) self.emp_2 = Employee('Sue', 'Smith', 60000) def tearDown(self): print('tearDown\n') def test_email(self): print('test_email') self.assertEqual(self.emp_1.email, '*****@*****.**') self.assertEqual(self.emp_2.email, '*****@*****.**') self.emp_1.first = 'John' self.emp_2.first = 'Jane' self.assertEqual(self.emp_1.email, '*****@*****.**') self.assertEqual(self.emp_2.email, '*****@*****.**') def test_fullname(self): print('test_fullname') self.assertEqual(self.emp_1.fullname, 'Corey Schafer') self.assertEqual(self.emp_2.fullname, 'Sue Smith') self.emp_1.first = 'John' self.emp_2.first = 'Jane' self.assertEqual(self.emp_1.fullname, 'John Schafer') self.assertEqual(self.emp_2.fullname, 'Jane Smith') def test_apply_raise(self): print('test_apply_raise') self.emp_1.apply_raise() self.emp_2.apply_raise() self.assertEqual(self.emp_1.pay, 52500) self.assertEqual(self.emp_2.pay, 63000) def test_monthly_schedule(self): with patch('Employee_class.requests.get') as mocked_get: mocked_get.return_value.ok = True mocked_get.return_value.text = 'Success' schedule = self.emp_1.monthly_schedule('May') mocked_get.assert_called_with('http://company.com/Schafer/May') self.assertEqual(schedule, 'Success') mocked_get.return_value.ok = False schedule = self.emp_2.monthly_schedule('June') mocked_get.assert_called_with('http://company.com/Smith/June') self.assertEqual(schedule, 'Bad Response!')