• Python单元测试


    import unittest
    
    def get_formatted_city_name(city, country, population=''):
        '''fanhui'''

    if population: full_name = city + ", " + country + ' - ' + 'population ' + str(population) else: full_name = city + ", " + country return full_name.title() class CityTestCase(unittest.TestCase): '''sadsa''' def test_cities(self): full_name = get_formatted_city_name('hz', 'china') self.assertEqual(full_name, "Hz, China") def test_cities_population(self): full_name = get_formatted_city_name('hz', 'china', 1200000) self.assertEqual(full_name, 'Hz, China - Population 1200000') unittest.main()

    unittest Module 中的断言方法

    方法 用途
    assertEqual(a,  b) 核实 a == b 
    assertNotEqual(a, b) 核实 a != b
    assertTrue(x) 核实x为True
    assertFalse(x) 核实x为False
    assertIn(item , list ) 核实item在list中
    assertNotIn(item , list )

    核实item不在list中

  • 相关阅读:
    Gym
    HDU
    HDU
    POJ
    洛谷P3690 Link Cut Tree (动态树)
    Gym
    P4294 [WC2008]游览计划 (斯坦纳树)
    洛谷P3264 [JLOI2015]管道连接 (斯坦纳树)
    HDU
    Controller调试接口
  • 原文地址:https://www.cnblogs.com/Template/p/9455394.html
Copyright © 2020-2023  润新知