python 几种常见的测试框架

时间:2024-11-11 09:07:14

1. unittest

参考文档: https://docs.python.org/3/library/unittest.html

The unittest unit testing framework was originally inspired by JUnit and has a similar flavor as major unit testing frameworks in other languages. It supports test automation, sharing of setup and shutdown code for tests, aggregation of tests into collections, and independence of the tests from the reporting framework.

跟 JUnit类似。

2. unittest2

参考文档: https://pypi.python.org/pypi/unittest2

unittest2 is a backport of the new features added to the unittest testing framework in Python 2.7 and onwards.

unittest2 是一个针对 unittest测试框架新特性的补丁。

3. pytest

参考文档:http://pytest.org/latest/

unittest is the Python standard library testing framework. It is sometimes known as PyUnit and has a rich heritage as part of the xUnit family of testing libraries.

也就是说 pytest 就是 unittest。

4. nose

参考文档: https://nose.readthedocs.org/en/latest/

基于Python的测试驱动开发实战 也有nose的用法: http://python.jobbole.com/81305/

nose extends unittest to make testing easier.

nose扩展了unittest,从而使得测试更容易。

5. doctest

参考文档:https://docs.python.org/3/library/doctest.html

Python 各种测试框架简介(一):doctest  http://my.oschina.net/lionets/blog/268542

The doctest module searches for pieces of text that look like interactive Python sessions, and then executes those sessions to verify that they work exactly as shown.

doctest模块会搜索那些看起来像交互式会话的 Python 代码片段,然后尝试执行并验证结果。