Python单元测试相关的模块和工具
任何语言,要想编写足够健壮的程序,都要配合完善的单元测试,尤其是大型项目,在实践中这也是容易被忽略或不重视的一个环节。在此收集单元测试相关的模块和学习书籍、阅读资料等。
作为动态类型的编程语言,Python没有静态类型检测,直到真正运行时才会抛相应异常。这或许是动态语言灵活高效的一点代价。实际上无论动态语言、静态语言,要获得更好的鲁棒性,都离不开编写完善的单元测试。
The only way to have confidence in a Python program is to write tests.
from 《Effective Python: 59 Specific Ways to Write Better Python》
Python中测试和覆盖率相关的模块有:
- hypothesis-python
- doctest
- unittest
- mock
- pytest
- nose
- nose2
- coverage
- pytest-cov
- pyresttest
- pytest-dockerpy
- python-afl
阅读书籍:
- 《Python Testing with pytest》
- 《Python Testing Cookbook》
- 《Learning Python Testing》
- 《Testing Python: Applying Unit Testing, TDD, BDD and Acceptance Testing》
阅读资料:
- Testing Your Code
- Flask and Pytest coverage
- What’s the best way to learn about TDD in Python?
- nose introduction
- System Testing with pytest and docker-py
- Python代码覆盖率分析工具Coverage
- 用 Python 编写干净、可测试、高质量的代码
- coverage.py的覆盖率统计原理
- Python 的单元测试之 tox
- 从自动化测试到持续部署,你需要了解这些
- 单元测试要做多细?
- TDD并不是看上去的那么美
PyCon Talks:
- Next Level Testing PyCon 2017
- Better Testing With Less Code: Property Based Testing With Python - PyCon 2016
The Python Test Podcast:
The best way to learn is by doing, so go have a try.