单元测试的目的就是写一些测试的case,Python框架会自动去调用,并给出结果。
# encoding: utf-8
import unittest
def get_formatted_name(first, last):
"""Generate a neatly formatted full name."""
full_name = first + ' ' + last
return full_name.title()
class NamesTestCase(unittest.TestCase):
"""测试name_function.py"""
def test_first_last_name(self):
formatted_name = get_formatted_name("lebron", "james")
self.assertEqual(formatted_name, "Lebron James")
unittest.main()
--结果如果通过会给出.,并给出运行的时间
.
----------------------------------------------------------------------
Ran 1 test in 0.000s