zoukankan      html  css  js  c++  java
  • python unittest学习3---添加测试套件,testsuit

    一下例子即把testcase添加到suit里面

    import unittest

    class TestStringMethods(unittest.TestCase):
        def test_upper(self):
            self.assertEqual("foo".upper(), "FOO")
        def test_isupper(self):
            self.assertTrue("FOO".isupper())
            self.assertFalse("Foo".isupper())
        def test_split(self):
            s="hello world"
            self.assertEqual(s.split(),["hello","world"])


    def suite():
        suite=unittest.TestSuite()
        suite.addTest(TestStringMethods("test_upper"))
        suite.addTest(TestStringMethods("test_isupper"))
        return suite

    if __name__=="__main__":
        runner=unittest.TextTestRunner()
        runner.run(suite())

    此时运行时,就会跑test_upper,test_isupper

    备注:添加的测试用例必须是按照基础类TestCase创建出来的测试用例,如果只是单个方法,添加时会报错

  • 相关阅读:
    母函数
    匈牙利算法
    AC 自动机
    MFC Invalidate闪屏问题
    求解x=a^b(mod m)
    Millar_rabin和Pollard_Rho
    图论入门算法理解
    Numpy 库常用函数大全
    Linux 系统中“|”管道的作用是什么
    win10 万能修复公式
  • 原文地址:https://www.cnblogs.com/dmtz/p/10969106.html
Copyright © 2011-2022 走看看