单元测试的目的就是写一些测试的case,Python框架会自动去调用,并给出结果。

  1. # encoding: utf-8
  2. import unittest
  3. def get_formatted_name(first, last):
  4. """Generate a neatly formatted full name."""
  5. full_name = first + ' ' + last
  6. return full_name.title()
  7. class NamesTestCase(unittest.TestCase):
  8. """测试name_function.py"""
  9. def test_first_last_name(self):
  10. formatted_name = get_formatted_name("lebron", "james")
  11. self.assertEqual(formatted_name, "Lebron James")
  12. unittest.main()
  13. --结果如果通过会给出.,并给出运行的时间
  14. .
  15. ----------------------------------------------------------------------
  16. Ran 1 test in 0.000s

image.png

setup