zoukankan      html  css  js  c++  java
  • pythonunittest(10)

    迭代测试边界条件

    Testing corner cases by iteration
    While developing code, new corner case inputs are often discovered. Being able to capture
    these inputs in an iterable array makes it easy to add related test methods.

    1. Create a new file called recipe10.py in which to put all our code for this recipe.

    2. Pick a class to test. In this recipe, we'll use another variation of our Roman numeral
    converter. This one doesn't process values greater than 4000.

    3. Create a test class to exercise the Roman numeral converter.

    4. Write a test method that exercises the edges of the Roman numeral converter.

    5. Create a test method that exercises the tiers converting from decimal to Roman
    numerals.

    6. Create a test method that exercises a set of invalid inputs.

    7. Code a utility method that iterates over the edge cases and runs different assertions
    based on each edge.

    8. Make the script runnable by loading the test case into TextTestRunner.

    9. Run the test case.

    测试代码:

    Code

    结果输出:

    test_bad_inputs (__main__.RomanNumeralTest) ... Converting None to ...
    Converting 1.2 to I...
    Converting (None,), expecting <type 'exceptions.TypeError'>
    Converting (1.2,), expecting <type 'exceptions.TypeError'>
    ok
    test_edges (__main__.RomanNumeralTest) ... Converting 1 to I...
    Converting 0 to ...
    Converting -1 to ...
    Converting 4000 to MMMM...
    Converting (4001,), expecting <type 'exceptions.Exception'>
    Converting I to 1...
    Converting  to 0...
    Converting MMMM to 4000...
    Converting ('MMMMI',), expecting <type 'exceptions.Exception'>
    ok
    test_tiers (__main__.RomanNumeralTest) ... Converting 5 to V...
    Converting 9 to VIIII...
    Converting 10 to X...
    Converting 11 to XI...
    Converting 49 to XXXXVIIII...
    Converting 50 to L...
    Converting 51 to LI...
    Converting 99 to LXXXXVIIII...
    Converting 100 to C...
    Converting 101 to CI...
    Converting 499 to CCCCLXXXXVIIII...
    Converting 500 to D...
    Converting 501 to DI...
    Converting 1000 to M...
    ok

    ----------------------------------------------------------------------
    Ran 3 tests in 0.001s

    OK

  • 相关阅读:
    STM32F401+nRF24L01无线传输音频(对讲机原型)
    Keil MDK STM32系列(五) 使用STM32CubeMX创建项目基础结构
    Keil MDK STM32系列(四) 基于抽象外设库HAL的STM32F401开发
    Keil MDK STM32系列(三) 基于标准外设库SPL的STM32F407开发
    PlatformIO下的STM32F4xx项目配置
    nRF24L01基于FIFO TX队列的发送性能优化
    个人发展计划IDP 与Smart原则
    IDEA Maven 项目默认编译项目为JDK 1.5
    投资 学习 成长 判断力 面对挫折
    投资 价值 道德 长期主义(5,10,20年)三观
  • 原文地址:https://www.cnblogs.com/luhouxiang/p/2560416.html
Copyright © 2011-2022 走看看