The More Detailed Five: SWIFT Tests
I like to use five criteria to evaluate test quality. I’ve even managed to turn them into an acronym that is only slightly contrived: SWIFT.
-
Straightforward
-
Well defined
-
Independent
-
Fast
-
Truthful
Let’s explore those in more detail.
[S]traightforward
A test is straightforward if its purpose is immediately understandable.
Straightforwardness in testing goes beyond just having clear code. A straightforward test is also clear about how it fits into the larger test suite. Every test should have a point: it should test something different from the other tests, and that purpose should be easy to discern from reading the test.
Here is a test that is not straightforward:
| ## Don't do this |
| it "should add to 37" ... |
Get Rails 4 Test Prescriptions now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.