zoukankan      html  css  js  c++  java
  • unittest单元测试流程

    整理了一个单元测试的完整流程,觉得很不错。

    一个 test case
    类应该派生自 unittest.TestCase正常的的test case的调用顺序为

     

    from __future__ import print_function
    import unittest
     
    def setUpModule():
        print("setUpModule")
      
    def tearDownModule():
        print("tearDownModule")
         
    class MyTestCase(unittest.TestCase):
     
        def setUp(self):
            super(MyTestCase, self).setUp()
            self.addCleanup(self.my_cleanup)
             
            print()
            print("++++ setup")
     
        def tearDown(self):
            super(MyTestCase, self).tearDown()
            print("++++ tearDown")
            raise Exception()
             
        def my_cleanup(self):
            print("++++ my_cleanup")
             
        def test_case_1(self):
            print("++++ test case 1")
     
        def test_case_2(self):
            print("++++ test case 2")
               
        @classmethod
        def setUpClass(cls):
            print("setUpClass")
     
        @classmethod
        def tearDownClass(cls):
            print()
            print("tearDownClass")

    运行结果
    setUpModule
    setUpClass
     
    ++++ setup
    ++++ test case 1
    ++++ tearDown
    ++++ my_cleanup
     
    ++++ setup
    ++++ test case 2
    ++++ tearDown
    ++++ my_cleanup
     
    tearDownClass
    tearDownModule

    来自 <http://www.2cto.com/kf/201409/330721.html>

  • 相关阅读:
    GOF23设计模式汇总
    获取表单提交MVC错误信息
    Spring.Net
    简单工厂、工厂方法和抽象工厂
    Json和JsonP
    mysql8无法用navicat连接(mysql8加密方式的坑)
    (4.16)mysql备份还原——物理备份之XtraBackup实践
    mysql如何下载历史版本?
    如何测试端口通不通(四种方法)
    linux移动复制删除命令
  • 原文地址:https://www.cnblogs.com/semishigure/p/7283411.html
Copyright © 2011-2022 走看看