Unit testing is interesting because you often need to explain why the expected value is what it is.

Sometimes you need comments, but often you can also do it in code.


total_objs = Object.objects.filter(**test_criteria).count()
self.assertEqual(total_objs, 100) # 45 obj_a + 45 obj_b + 10 obj_c

Versus a well documented (in code) test:

total_objs = Object.objects.filter(**test_criteria).count()
expected_value = len(obj_a) + len(obj_b) + len(obj_c)
self.assertEqual(total_objs, expected_value)

It may take a couple extra lines, but being explicit about where values come from is always worth it.

Top writer in Technology | Backend Web Developer | bennettgarner.com

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store