What should be tested in Django Forms?
When testing Django Forms, what are the main things you should be testing? I know that if you write custom save() or clean_ methods, you should definitely make sure those are working correctly, but is it also good to check things like whether the fields you expect to be required are ac开发者_如何学Ctually required? Is that going overboard, since you don't want to test that Django is treating "required" fields correctly, and is more behavior testing?
"Test everything that can go wrong," they say.
But then the question is, "what can go wrong?"
Murphy's law states that everything that can go wrong, will go wrong.
But wouldn't it be paranoid to test everything that can go wrong according to Murphy? And writing tests for every single thing is not very productive. "Let's write a test that checks for parity errors in the hard disk's cache memory!" is probably not a good suggestion if you're developing a web browser.
The purpose of unit tests is to test your code. You're not writing tests for Django. If you assume that Django works correctly with regard to required fields, there's no need to test that.
In behavioural tests on the other hand, I'd say it's more OK to test things that are implemented by the framework. This is because behavioural tests are less transparent (less "white box") than unit tests, so the tests don't "know" whether something is implemented by a framework or by your code. Still, don't test the silly things if you have better things to do.
精彩评论