Are there any guidelines for writing test-friendly Python code?
What I believe:
- One method does one thing.
- Don’t use side-effects.
Any other suggestions?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
TDD
The best tip I can give you to write test friendly code is to write the tests first. Then write the production code (TDD). Uncle Bob devised three simple rules to write TDD:
Especially this quote should sink in:
Writing Testable Code
Also read "Writing Testable Code" from google’s testing expert(are for java, but also apply to python for large parts). You should also download/read the complete PDF on that page. But a quick recap: