Can we get rid of weird test assertions? #494
lunkwill42
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Re: These assertions which flashed by my screen in a recent pull request (they were not added as part of this PR):
Argus/tests/incident/test_views.py
Line 65 in adcaad7
Argus/tests/incident/test_views.py
Lines 72 to 73 in adcaad7
Argus/tests/incident/test_views.py
Line 86 in adcaad7
Argus/tests/incident/test_views.py
Line 90 in adcaad7
I strongly believe these assertions are asinine. Tests should fail for a single reason, but these tests have multiple assertions, and these particular ones have no bearing on what those tests are purported to do. They rather force the test into situation where it would fail if it happened to run on a non-clean database - and yet, you wouldn't expect the function under test to actually be considered as failing if the database isn't empty. The exercised code must always always work with a fully populated database, so let's not have the tests fail too.
Tests should follow the arrange-act-assert pattern. First, arrange the test. Act. Then assert the results. A goal should be to have as few assertions in a test as possible (1 would be ideal).
Beta Was this translation helpful? Give feedback.
All reactions