Feb-16-2019, 09:50 PM
(This post was last modified: Feb-16-2019, 09:56 PM by FWendeburg.)
Hi, i have been trying the unittest.TestCase class but when I tried it using this python program it somehow says the assertion it's wrong.
employee.py
Thanks in advance!
employee.py
class Employee(): """Manages an employee's information.""" def __init__(self, first_name, last_name, annual_salary): """Initializes the Employee class.""" self.first_name = first_name self.last_name = last_name self.annual_salary = int(annual_salary) def give_raise(self, raise_amount=5000): """Adds a number to the employee annual salary.""" if raise_amount: int(raise_amount) self.annual_salary += raise_amount else: self.annual_salary += 5000 return self.annual_salaryemployee_test.py
import unittest from employee import Employee class TestEmployee(unittest.TestCase): """Testing the Employee class.""" def setUp(self): """Creates an instance which will be used to tst the class""" self.employee_one = Employee('Francisco', 'Wendeburg', 500000) self.salary_rise = 100000 def test_employee_default_raise(self): """Will the default raise work?""" self.employee_one.give_raise() self.assertEqual(self.employee_one, 505000) def test_employee_given_raise(self): """Will test if input raise is working.""" self.employee_one.give_raise(self.salary_rise) self.assertEqual(self.employee_one, 600000) unittest.main()The error:
Error:FF
======================================================================
FAIL: test_employee_default_raise (__main__.TestEmployee)
Will the default raise work?
----------------------------------------------------------------------
Traceback (most recent call last):
File "C:\Users\Franc\Documents\python_work\chapter_eleven\employee\employee_test.py", line 16, in test_employee_default_raise
self.assertEqual(self.employee_one, 505000)
AssertionError: <employee.Employee object at 0x02AC5F30> != 505000
======================================================================
FAIL: test_employee_given_raise (__main__.TestEmployee)
Will test if input raise is working.
----------------------------------------------------------------------
Traceback (most recent call last):
File "C:\Users\Franc\Documents\python_work\chapter_eleven\employee\employee_test.py", line 22, in test_employee_given_raise
self.assertEqual(self.employee_one, 600000)
AssertionError: <employee.Employee object at 0x02AC5FF0> != 600000
----------------------------------------------------------------------
Ran 2 tests in 0.003s
FAILED (failures=2)
[Finished in 1.6s]
Linter
Severity Provider Description Line
Git
GitHub
Initialize a new project directory with a Git repository
Create repository
Thanks in advance!