参考:http://pythonguidecn.readthedocs.io/zh/latest/writing/tests.html
进行整理总结,供自己后续使用:
- 单元测试 unittest
import unittest
创建测试用例通过继承 unittest.TestCase 来实现. - 文档测试 doctest
import doctest
doctest.testmod()
利用函数的docstring 进行测试
3. 工具 py.test
pip install pytest
要比单元测试模型中相同功能所要求的工作量少得多。
4. Nose
pip install nose
nose自动化测试发现并节省人工创建测试组件的麻烦。它也提供各种插件,例如xUnit兼容性测试输出,覆盖度报告和测试选择。
5. tox
pip install tox
tox允许通过简单的初始化样式配置文件,配置复杂的多参数测试矩阵。
6. Unittest2
Unittest2是Python2.7中unittest模型的补丁,它的API有所改善,并且对Python之前版本中已有的内容有了更好的说明。
7. mock
unittest.mock 是Python中用于测试的一个库
pip install mock