python - Creating a Unittest -


hey i'm pretty new python , i'm trying create unit test code , i'm running lot of trouble, honest i'm wondering if code testable.

"""  core employee class """   class employee(object): empcount = 0  def __init__(self, name, salary, debt, takehome):     self.name = name     self.salary = salary     self.debt = debt     self.takehome = takehome  def display_employee(self):     print "name : ", self.name, ",salary: ", self.salary, "debt: ", \         self.debt, "take home: ", self.takehome   emp1 = employee("scott", 2000, 200, 2000-200)  emp2 = employee("mary", 5000, 300, 5000-300)  emp3 = employee("sam", 4000, 700, 4000-700)  emp4 = employee("sarah", 7000, 2000, 7000-200)  emp5 = employee("charlie", 10000, 5000, 10000-5000)  emp6 = employee("tony", 16000, 20000, 16000-20000)   employees = [emp1, emp2, emp3, emp4, emp5, emp6]   employee in employees:     employee.display_employee()   employee.empcount = len(employees)  print "total employees %d" % employee.empcount} 

if give me hand appreciated, tips if need change code run unittests on more

i think class testable. tests trivial since have ˋ__init__` method , display method.

the starting unit testing using unittest library.

write single test function each "public" method:

class testemployee(unittest.testcase):     def test_init(self):         ...      def test_display_employee(self):         ... 

there lots of tutorials on internet, @ one: testing code.

see also: python testing


Comments

Popular posts from this blog

javascript - Thinglink image not visible until browser resize -

firebird - Error "invalid transaction handle (expecting explicit transaction start)" executing script from Delphi -

mongodb - How to keep track of users making Stripe Payments -