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 O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.