def city(city,country):
print(city + ',' + country)
full_city = city + ',' + country
return full_city.title()
---------------------------------------------
import unittest
from city_functions import city
class NamesTestCase(unittest.TestCase):
"""测试city_function.py"""
def test_city_country(self):
formatted_name = city('beijing', 'China')
self.assertEqual(formatted_name, 'Beijing,China')
unittest.main()
def city(city,country,population=5000000):
print(city + ',' + country)
full_city = city + ',' + country + ' - population ' + str(population)
return full_city.title()
---------------------------------------------
import unittest
from city_functions import city
class NamesTestCase(unittest.TestCase):
"""测试city_function.py"""
def test_city_country_population(self):
formatted_name = city('beijing', 'China')
self.assertEqual(formatted_name, 'Beijing,China - Population 5000000')
unittest.main()
class Employee():
def __init__(self,first_name,last_name,salary):
self.first_name = first_name
self.last_name = last_name
self.salary = int(salary)
self.Raise = 5000
def give_raise(self):
self.salary += self.Raise
return self.salary
---------------------------------------------
import unittest
from Employee import Employee
class NamesTestCase(unittest.TestCase):
"""测试city_function.py"""
def setUp(self):
self.employee = Employee('ergou', 'yang','5000')
self.Raise_setup = [5000,6000]
def test_give_default_raise(self):
self.assertEqual(self.employee.give_raise(), 10000)
def test_give_custom_raise(self):
self.employee.Raise = self.Raise_setup[1]
self.assertEqual(self.employee.give_raise(), 11000)
unittest.main()