zoukankan      html  css  js  c++  java
  • python-unitetest-unittest 的几种执行方式

    #unittest-test.py

    import unittest
    from demo import RunMain
    import HtmlTestRunner

    class TestMethod(unittest.TestCase):
    #类方法

    @classmethod
    def setUpClass(cls):
    print("类执行之前的方法")

    @classmethod
    def tearDownClass(cls):
    print("类执行之后的方法")


    #每次方法之前执行
    def setUp(self):
    print("setup")

    def test_01(self):

    url_p = "https://easy-mock.com/mock/5d0cce9536b12b2b2e62adc7/example/upload"
    data = {
    "hello":"world",
    "botoo":"123"
    }

    res = RunMain(url_p,"POST",data).res
    #print(res)
    self.assertIn("undefined_http",str(res['data']))
    globals()['img'] = res['data']['img'] #加入缓存

    def test_02(self):
    print(img)

    url_g ="https://easy-mock.com/mock/5d0cce9536b12b2b2e62adc7/example/query"
    res = RunMain(url_g,"GET").res
    self.assertEqual("hah",res['data']['name'])
    #print(res)

    @unittest.skip
    def test_03(self):
    print(img)

    #每次方法之后执行
    def tearDown(self):
    print("teardown")


    if __name__ == "__main__":
    """
    #方法一:
    unittest.main()
    """

    """
    #方法二:
    #加入容器中执行
    suite=unittest.TestSuite()
    suite.addTest(TestMethod("test_01"))
    suite.addTest(TestMethod("test_02"))
    suite.addTest(TestMethod("test_03"))
    unittest.TextTestRunner().run(suite)
    """

    """
    #方法三:
    #加入测试报告,执行所有case
    unittest.main(testRunner=HtmlTestRunner.HTMLTestRunner(output='example_dir'))
    """

    """
    #方法四:
    #加入测试报告,执行加入容器的case
    suite = unittest.TestSuite()
    suite.addTest(TestMethod("test_01"))
    suite.addTest(TestMethod("test_02"))
    suite.addTest(TestMethod("test_03"))
    testRunner=HtmlTestRunner.HTMLTestRunner(output='example_dir')
    testRunner.run(suite)
    """

  • 相关阅读:
    java三层架构:持久层、业务层、表现层
    Spring:Spring JDBCTemplate & 声明式事务
    Spring:AOP
    Spring:IOC控制反转
    Mybatis: 加载策略及注解开发
    Mybatis 配置文件深入
    Mybatis:基本应用
    前后端项目接口联调
    springboot整合jsp
    IDEA出现URI is not registered (Settings | Languages & Frameworks | Schemas and DTDs)
  • 原文地址:https://www.cnblogs.com/zhaocbbb/p/12789234.html
Copyright © 2011-2022 走看看