3 points · by mattberjon · 9y ago · 4 comments
I'm trying to become better at unit testing (especially in python) but I'm struggling to write effective tests or even just writing tests on functions that return nothing or need to be mocked. I read articles on the subject, watched conferences and read the documentation of py.test and I still have difficulties because usually test cases shown are really simple. Would you have interesting resources to share on the matter?
Thanks a lot
If you've listened to 'uncle' Bob Martin, you've probably seen him advocate writing tests first (if you haven't listened to him and you're interested in testing, he has an experienced view whether or not you wind up agreeing with him). Writing tests before the code means that the code will either be testable or it will be wrong (it might be testable and still wrong but there's a chance that the tests will show that).
Anyway, I suppose my point is that if I don't know how to test my code, the problem is probably the quality of my code not my knowledge of testing. Perhaps complex testing techniques are a code smell for complicated programs. Or not.