1

I'm not certain if I'm missing something completely obvious, but every time I call upon unittest.main() my commandline output reads out:

Ran 0 tests in 0.000s

It should say that I've run two tests, though, given the code here:

import unittest
from Chap11Lesson2 import Employee
 class EmployeeTest(unittest.TestCase):
 def setUp(self):
 """Setting up a variable for use in the test methods"""
 self.employee1 = Employee("Lucas", "Grillos", 20000)
 def give_default_raise(self):
 """Testing to see if 5000 is added properly"""
 money = 25000
 self.employee1.give_raise()
 self.assertEqual(self.employee1.salary, money)
 def give_custom_raise(self):
 """Testing to see if 10000 is raised properly"""
 money = 35000
 self.employee1.give_raise(10000)
 self.assertEqual(self.employee1.salary, money)
unittest.main()

Here's the class that it's testing from:

class Employee():
 def __init__(self, first_name, last_name, salary):
 self.first_name = first_name
 self.last_name = last_name
 self.salary = salary
 def give_raise(self, salary_raise = None):
 if salary_raise:
 self.salary = self.salary + salary_raise
 else:
 self.salary = self.salary + 5000
 def print_salary(self):
 print(self.salary)

I've never had a problem like this before, so I'm not certain what to do. I'm learning Python from Eric Matthes' Python Crash Course, the 2016 edition, if that's any reference. This problem hasn't appeared in the other lessons that I've done from it either.

Here's what I've tried:

I've tried fiddling around with the give_raise(self, salary_raise=None) method, and changing up how that worked in case I had messed something up internally there but I don't see why that would affect the testing.

I've tried deleting it and rewriting it once again (since it's not a lot of code) in hopes that I just forgot something silly, but if I did then I forgot it a second time.

Apologies in advance if it's a very simple fix, and apologies if there's anything wrong with the way I've formatted this question, or if this isn't a forum for questions like this--this is my first time posting here.

asked Nov 10, 2017 at 22:22
2
  • I apologize that I didn't add docstrings to my functions for clarification on what they do. Commented Nov 10, 2017 at 22:25
  • prefix your test methods with 'test' to get them to run. Commented Nov 10, 2017 at 22:31

3 Answers 3

1

Test methods need to have names beginning with test_ for the unittest runner to find them.

Call your tests test_give_default_raise and test_give_custom_raise.

answered Nov 10, 2017 at 22:25
Sign up to request clarification or add additional context in comments.

1 Comment

I knew it would be something stupid I forgot to do... Thanks so much for you help in any case, Daniel.
0

The class EmployeeTest(unittest.TestCase):, should have test_ methods to be run the unittest module. so try this:

import unittest
from Chap11Lesson2 import Employee
class EmployeeTest(unittest.TestCase):
 def setUp(self):
 """Setting up a variable for use in the test methods"""
 self.employee1 = Employee("Lucas", "Grillos", 20000)
 def test_give_default_raise(self):
 """Testing to see if 5000 is added properly"""
 money = 25000
 self.employee1.give_raise()
 self.assertEqual(self.employee1.salary, money)
 def test_give_custom_raise(self):
 """Testing to see if 10000 is raised properly"""
 money = 35000
 self.employee1.give_raise(10000)
 self.assertEqual(self.employee1.salary, money)
unittest.main()
answered Nov 10, 2017 at 22:27

Comments

0

Change your method names so they're prefixed with 'test' for the test methods and it should run.

answered Nov 10, 2017 at 22:30

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.