1.python函数测试:
创建文件:
def get_formatted_name(first, last, middle=''):
"""Generate a neatly-formatted full name."""
if middle:
full_name = first + ' ' + middle + ' ' + last
else:
full_name = first + ' ' + last
return full_name.title()
测试:
import unittest #先创建'name_function.py'文件.
from name_function import get_formatted_name
class NamesTestCase(unittest.TestCase):
"""Tests for 'name_function.py'."""
def test_first_last_name(self):
formatted_name = get_formatted_name('janis', 'joplin')
self.assertEqual(formatted_name, 'Janis Joplin')
unittest.main()
输出:.
----------------------------------------------------------------------
Ran 1 test in 0.000s
OK
|