Bryan Says...

Rants, opinions, and other stuff I find interesting.

If your tests don’t scale, you might want to look in the mirror

“Our test suite is slow”

“Our test suite is fragile”

You have to approach your test suite the same way you approach your application. In many cases, people don’t pay enough attention to your test suites. There are only a few guidelines to follow to have sane test suites that run in a decent amount of time.

1. Be careful what you mock. Mocks are deposits on future pain. Sure they speed up execution, but they aren’t resilient to changes you’ve made in other sections of your code.
2. Don’t talk to external services unless you absolutely need to.
3. I bet the box you run your tests on uses multiple cores. Why not introduce a test runner that can actually take advantage of it.
4. Only create just enough setup to actually test your behavior.
5. Be observant of side effects. If you are using something like factory girl, models will be created and run callbacks. Is that really important to what you are testing?

There are techniques you can try that will allow you to reduce test times significantly. Don’t let your previous failures or perceived inabilities trick you into thinking it isn’t possible. Testing most definitely scales. I guarantee it!

If all else fails, just drop me a line. I’m sure I can help steer you in a better direction.

  • Anonymous


  • Bob

    Which test runners allow for multiple cores?

  • bryanl

    Start here:

  • Suraj Kurapati

    And finish here: :P