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

    在测试模块中定义测试套件

    Defining test suites inside the test module.

    Each test module can provide one or more methods that define a different test suite. One
    method can exercise all the tests in a given module; another method can define a particular
    subset.

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

    2. Pick a class to test. In this case, we will use our Roman numeral converter.

    3. Create a test class using the same name as the class under test with Test appended
    to the end.

    4. Write a series of test methods, including a setUp method that creates a new
    instance of the RomanNumeralConverter for each test method.

    5. Create some methods in the recipe's module (but not in the test case) that define
    different test suites.

    6. Create a runner that will iterate over each of these test suites and run them through
    unittest's TextTestRunner.

    7. Run the combination of test suites, and see the results.

    测试代码:

    Code

    输出结果:

    Running test suite 'high_and_low'
    test_parsing_millenia (__main__.RomanNumeralConverterTest) ... ok
    test_parsing_one (__main__.RomanNumeralConverterTest) ... ok

    ----------------------------------------------------------------------
    Ran 2 tests in 0.000s

    OK
    Running test suite 'combos'
    test_combo1 (__main__.RomanNumeralConverterTest) ... ok
    test_combo2 (__main__.RomanNumeralConverterTest) ... ok
    test_combo3 (__main__.RomanNumeralConverterTest) ... ok

    ----------------------------------------------------------------------
    Ran 3 tests in 0.000s

    OK
    Running test suite 'all'
    test_combo1 (__main__.RomanNumeralConverterTest) ... ok
    test_combo2 (__main__.RomanNumeralConverterTest) ... ok
    test_combo3 (__main__.RomanNumeralConverterTest) ... ok
    test_empty_roman_numeral (__main__.RomanNumeralConverterTest) ... ok
    test_no_roman_numeral (__main__.RomanNumeralConverterTest) ... ok
    test_parsing_century (__main__.RomanNumeralConverterTest) ... ok
    test_parsing_decade (__main__.RomanNumeralConverterTest) ... ok
    test_parsing_half_century (__main__.RomanNumeralConverterTest) ... ok
    test_parsing_half_decade (__main__.RomanNumeralConverterTest) ... ok
    test_parsing_millenia (__main__.RomanNumeralConverterTest) ... ok
    test_parsing_one (__main__.RomanNumeralConverterTest) ... ok

    ----------------------------------------------------------------------
    Ran 11 tests in 0.001s

    OK

  • 相关阅读:
    (转)ELK Stack 中文指南--性能优化
    (转)如何在CentOS / RHEL 7上安装Elasticsearch,Logstash和Kibana(ELK)
    (转)GlusterFS 01 理论基础,企业实战,故障处理
    (转)CentOS7.4环境下搭建--Gluster分布式集群存储
    (转)DB2性能优化 – 如何通过调整锁参数优化锁升级
    (转)架构师之DNS实战CentOS7VSCentOS6
    PHP:计算文件或数组中单词出现频率
    [获取行数]php读取大文件提供性能的方法,PHP的stream_get_line函数读取大文件获取文件的行数的方...
    Windows下配置环境变量和需不需要重启问题
    CENTOS 下安装APK反编译工具 APKTOOL
  • 原文地址:https://www.cnblogs.com/luhouxiang/p/2560247.html
Copyright © 2011-2022 走看看