Python-Learning-UnitTest

To achieve this, unittest supports some important concepts:

test fixture
A test fixture represents the preparation needed to perform one or moretests, and any associate cleanup actions. This may involve, for example,creating temporary or proxy databases, directories, or starting a serverprocess.
test case
A test case is the smallest unit of testing. It checks for a specificresponse to a particular set of inputs. unittest provides a base class, TestCase, which may be used to create new test cases.
test suite
A test suite is a collection of test cases, test suites, or both. It isused to aggregate tests that should be executed together.
test runner
A test runner is a component which orchestrates the execution of testsand provides the outcome to the user. The runner may use a graphical interface,a textual interface, or return a special value to indicate the results ofexecuting the tests.

  • 详解Python的单元测试 (Quote)  
    单元测试可以有效地测试某个程序模块的行为,是未来重构代码的信心保证。

    单元测试的测试用例要覆盖常用的输入组合、边界条件和异常。

    单元测试代码要非常简单,如果测试代码太复杂,那么测试代码本身就可能有bug。

    单元测试通过了并不意味着程序就没有bug了,但是不通过程序肯定有bug。


  • Questions
    1.  When using 'assertRaise' , the function is not executed.
      class TestSolver(TestCase):
          def test_negative_discr(self):
              s = Solver
              self.assertRaises(Exception,s.demo,3,0,1) #s.demo not executed
          def test_demo(self):
              self.fail()


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值