Test

Pre

  1. What type of test are you going to write? e.g. Unit tests, functional tests …
  2. What do you test against? In other words, how do you tell a function works well? e.g. Functional testing is against the functional requirements/specifications
  3. Do you make any assumptions while development? If yes, each assumption should have a test such that if the assumption breaks, the test will also break (to raise people’s attention).

Framework

? Why framework
– better reporting
– sharing of setup and shutdown code for tests
– aggregation of tests into collections

? Basic component
1 TestRunner run (TestSuite / TestCase)
1 TestSuite n TestCase
1 TestCase n TestMethod

? How does a good testing framework look like
– appropriate abstraction layers
– meaningful logging and reporting structure
– easily maintainable and extendable
– retry mechanism to rerun failed tests

Python unittest
  • A testcase is created by subclassing unittest.TestCase
  • N test methods belong to 1 test case. A test mehod name should start with the letters test. That informs the test runner about which methods represent tests.
  • To run the tests:
    1. unittest.main() provides a command-line interface to the test script
    2. code below can make tests ran by interpreter or another script
      suite = unittest.TestLoader().loadTestsFromTestCase(testCaseClass) unittest.TextTestRunner(verbosity=2).run(suite)
      class unittest.TextTestRunner: A basic test runner implementation which prints results on standard error
      A test runner is an object that provides a single method, run(), which accepts a TestCase or TestSuite object as a parameter, and returns a result object.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值