I've been going through a lot of Django testing tutorials, but I'm a bit unsure as to how much to test. I'm primarily using classed based views
For instance, in testing my views, should I check all of the following:
- That every URL mapping is correct
- All views are using the expected template
- All views are using the expected form (if applicable)
- In every views that the expected context variables are there
- All posts redirect somewhere
Most of my views are class based views. I have a ListView, where I set the template_name, model and context_object_name. Should I be testing that these have been set correctly? There is no logic there so it seems a bit silly to test it since it is just configuration.
In testing models:
- Should I test that a validation error is raised when a field is marked as unique and I try to add another record with the same value for the field?
- If I add a MinValueValidator to a field, should I test that?
- I assume regex validators should be tested as there is logic there.
In testing forms (especially model forms)
- Should I check every field on a form that an error is generated for for invalid input?
- When an error is generated check the error message is correct?
- Test that a model forms saves an item correctly?
- There's tons of things that can potentially be testing for every field in the form, such as the help_text, place_holder etc.
A lot of these tests seems like I'm just testing configuration as opposed to logic. I know how to tests all the items as mentioned above, but when using class based views, the testing code can be 10x the amount of actuall code if I try to test everything.
So, my current idea is to test only places in my app where I add logic, not where it is only configuration. So if I override a method in a model form or in a view, I'll test that. Does this sound like a good approach or should I really be testing every little thing as mentioned above?
Aucun commentaire:
Enregistrer un commentaire