python自动化单元测试工具----doctest
2017-02-14 10:02
676 查看
unit testing
An automatic procedure used to validate that individual units of code are working properly. Python has doctest built in for this purpose.
doctest是python内置模块,用于进行简单的单元测试
Doctests在函数或脚本体的第一行写入三引号,由简单的解释语、一系列输入和期望输出组成。
doctest模块会自动执行由>>>开头的任何声明,然后输出结果与注释器的期望结果进行比较
Python has a built-in doctest module for easy unit testing. Doctests can be written within a triple quoted string on the first line of the body of a function or script. They consist of sample interpreter sessions with a series of inputs to a Python prompt followed by the expected output from the Python interpreter.
The doctest module automatically runs any statement begining with >>> and compares the following line with the output from the interpreter.
例:
运行结果:
An automatic procedure used to validate that individual units of code are working properly. Python has doctest built in for this purpose.
doctest是python内置模块,用于进行简单的单元测试
Doctests在函数或脚本体的第一行写入三引号,由简单的解释语、一系列输入和期望输出组成。
doctest模块会自动执行由>>>开头的任何声明,然后输出结果与注释器的期望结果进行比较
Python has a built-in doctest module for easy unit testing. Doctests can be written within a triple quoted string on the first line of the body of a function or script. They consist of sample interpreter sessions with a series of inputs to a Python prompt followed by the expected output from the Python interpreter.
The doctest module automatically runs any statement begining with >>> and compares the following line with the output from the interpreter.
例:
def is_divisible_by_2_or_5(n): """ >>> is_divisible_by_2_or_5(8) True >>> is_divisible_by_2_or_5(7) False >>> is_divisible_by_2_or_5(5) True >>> is_divisible_by_2_or_5(9) False """ return n % 2 == 0 or n % 5 == 0 if __name__ == '__main__': import doctest doctest.testmod()
运行结果:
c:\>python myfunctions.py -v Trying: is_divisible_by_2_or_5(8) Expecting: True ok Trying: is_divisible_by_2_or_5(7) Expecting: False ok Trying: is_divisible_by_2_or_5(5) Expecting: True ok Trying: is_divisible_by_2_or_5(9) Expecting: False ok 1 items had no tests: __main__ 1 items passed all tests: 4 tests in __main__.is_divisible_by_2_or_5 4 tests in 2 items. 4 passed and 0 failed. Test passed.
相关文章推荐
- Python Unittest 自动化单元测试框架Demo
- Python Unittest 自动化单元测试框架Demo
- Python Unittest自动化单元测试框架详解
- Python Unittest 自动化单元测试框架Demo
- Python doctest自动测试
- python测试——doctest和unittest
- Python 测试(一)—— doctest
- python 测试框架doctest
- Python自动化测试工具Splinter简介和使用实例
- RFT(Rational Functional Test)是IBM开发的一套自动化测试工具,可以测试web, GUI和console。
- Python测试框架doctest
- Python UnitTest 框架执行功能自动化测试
- appium2-基于python调用unittest框架对iOS进行自动化测试
- Python的文档测试(doctest)
- Python 各种测试框架简介(一):doctest
- python 自动化测试工具集
- Python进行自动化测试工具
- Python代码测试 - unitest\doctest\nose
- WIN7- selenium-python 自动化测试工具配置环境
- 31.Python的单元测试工具——doctest