I am very new to TDD and am trying to create my first Djagno application with tests. I am a bit confused when it comes to generic views. I have read several places (including the official docs) that each view should have tests associated with it. But I have also read that you should avoid testing Django internals because it is unnecessary.
So if I have a view like this:
class ClinicView(DetailView):
model = Clinic
template_name = "directory/clinic.html"
which uses a generic view and works fine, should I write a test for it?
My gut feeling is that I shouldn't have to because I use a generic view but haven't really found much to tell me if my feeling is correct. What are the best practices when it comes to this? Or what would be expected of me if I was to be giving my code over to be maintained by someone else? Should I at least write a test to make sure that my model and the template exist? Thanks in advance.
You want to avoid over-testing. You should only write tests for custom logic or for things that change frequently.
For example, if the Clinic model had a complex method which calculated some result, you would want tests to ensure this does what you think it does.
If you had something that you changed often and others may come in and change, you want tests to ensure that it is still functional after your change. The Django views are already tested. Unless you add a bunch of custom logic to the View (which you should probably be putting in a ModelManager anyway) there's no point to test it repeatedly with automated tests.
Testing is great and I love it! But I hate maintaining it, so I don't aim for full coverage. Once you cover your custom code with tests, you get diminishing returns by testing every little piece.
I once worked for a company that went a little crazy and wanted me to write tests for the automated tests. Don't be like them (: