Python 中是否有用于 TDD 的特定目录结构?
教程谈论的是测试的内容,而不是把它们放在哪里
从 Python Koans 中寻找,怀疑它是这样的:
/project/main_program.py # This has main method, starts program
/project/classes/<many classes>.py
/project/main_test.py # This simply directs unittest onto tests, can use parameters fed to it to customise tests for environment
/project/tests/<many tests>.py
# to run tests, type "python -m unittest main_test.py" (into a terminal)
# to run program, type "python main_program.py"
我这样做对吗?是否有一个很好的指南来教授 TDD 的目录层次结构?我听说混合代码和测试文件很糟糕。
引用资料:
- Are there any good online tutorials to TDD for an experienced programmer who is new to testing? # 编码道场?嗯……也许我会开始一个编码道场网站……
- http://onlamp.com/pub/a/python/2004/12/02/tdd_pyunit.html #显示混合文件
- http://www.youtube.com/watch?v=sD6qzJNQEpE #As great as pyTDDmon looks, I would like to understand the basics first =) 这也是一个混合文件
- http://www.slideshare.net/Skud/test-driven-development-tutorial #explains 仅“设计测试实现测试重复”..
- http://blog.cerris.com/category/django-tdd/ #仍然没有帮助...
- http://docs.python.org/library/unittest.html
最佳答案
根据您的项目,任何风格都可以
- 将实现代码与测试代码分开
- 轻松创建新测试
- 在一次操作中运行所有测试(例如回归测试)
python koans/etc 只是指南。最后,您希望通过单元测试支持 DRY,并能够轻松、可维护和直观地进行测试。最后由您决定文件夹结构。
我觉得您过于关注满足约定而不是满足您的项目。
关于Python TDD目录结构,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9859832/