Friday, September 23, 2011
Atomic tests are good. Not the Dr. Strangelove kind of atomic tests, I mean automated tests.
Atomic tests test one thing about the product. An atomic test can’t be broken up into smaller tests and still test the same thing, hence the “atomic” quality of the test. Atoms can’t be broken up into smaller pieces.
Atomic tests also must be independent of each other. They can be run individually or in groups, in any order, so they can be distributed and run faster than if they were run in a sequential set. Failures can be known, reported and acted on sooner (by humans or by an automated process).
A test that tests two things, A and B, risks not testing B at all because the test of A failed. So, to maximize test coverage, test B separately from A if possible. If it’s not possible to test B without testing A first (e.g. an end-to-end or E2E test) then be sure to test A without testing B as well (in an independent atomic test) to make the artifacts and reporting more clear and to eliminate any possibility of latent dependency of the test of A on the test of B.
So, if an E2E test requires running through A before testing B (e.g. “A” is creating an account, and “B” is doing some operation with that account) then there are at least two tests:
1. Test A: Create an account
2. Test B: Create an account, then do some operation with that account
Realizing business value with the automated tests includes some follow-up on the results, to ask questions like “have we seen this failure before?” (see this post http://metaautomation.blogspot.com/2011/09/persisting-artifacts-from-automated.html) The next favorite question of good testers is “can we do it again, to reproduce the same failure?” With atomic tests, failures are more reproducible because the tested actions are as simple as possible. Re-runs are quicker, too!
Adam Goucher writes about this here: http://adam.goucher.ca/?cat=3 “… a test case should only be measuring one, and only one thing.” and “Test cases should not be dependent on other test cases.” This isn’t a new idea in itself, but it’s a new thing to use the memorable term “atomic” as a simple rule for the team to follow.
… and if “atomic” isn’t memorable enough for you, stream the movie http://www.bing.com/search?q=%22dr+strangelove