Skip to content

Instantly share code, notes, and snippets.

@rubiii
Created June 26, 2012 13:31
Show Gist options
  • Save rubiii/2995814 to your computer and use it in GitHub Desktop.
Save rubiii/2995814 to your computer and use it in GitHub Desktop.
Slow tests are a code smell

Slow tests are a code smell

Measure your test performance with e.g. CI Reporter and refactor slow tests.

  1. Extract domain objects from your fat models. ActiveRecord is not your domain.
  2. Decouple code that doesn't follow the Single Responsibility Principle.
  3. Inject dependencies instead of referring to globals like Rails or User.

From my experience, tests that don't require "test_helper" reveal the coupling in your application. Object orientation is about objects sending messages to other objects. So my approach is to test the messages, but isolate the object under test using mocks/stubs and to write acceptance tests to verify the system as a whole.

Here are some resources that should get you started:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment