talira

TestProf

Ruby Tests Profiling Toolbox

open sourceMITself-hostablefree

TestProf is a collection of tools for finding and fixing what makes a Ruby test suite slow, for RSpec and Minitest. Its profilers report time spent in ActiveSupport events such as SQL queries (EventProf), setup time in before hooks and let (RSpecDissect), factory usage and unnecessary database writes (FactoryProf, Factory Doctor), memory spikes (MemoryProf) and tests per second by group (TPSProf), and it plugs into ruby-prof and stackprof. Its recipes speed tests up: before_all and let_it_be create data once per group, AnyFixture and FactoryDefault reuse shared records, and it ships RuboCop cops for slow test patterns. Evil Martians builds it.

Problems it solves

  • our RSpec suite takes 40 minutes and I can't tell which tests are the slow ones
  • find out how much of my test run is spent in database queries versus everything else
  • factories build whole graphs of associated records that a test never looks at
  • tests save records to the database when an unsaved or stubbed object would do
  • setup in before hooks and let blocks eats most of our test time
  • create expensive test data once per example group instead of once per example
  • a few spec files use so much memory that our CI runners run out
  • which test groups run the fewest tests per second, so we know where to start optimising
  • fail the build when a test group gets slower than a threshold
  • profile the test suite with stackprof or ruby-prof without wiring it up myself
  • see which factories run most often and how many extra records each one creates
  • run a random sample of the test suite to profile it quickly
  • lint our specs for patterns that make them slow
  • speed up a slow Minitest suite in a Rails app

Features

  • EventProf: time spent in ActiveSupport::Notifications events such as SQL queries
  • TagProf: time by test type or tag
  • Factory Doctor: finds tests that write to the database without needing to
  • FactoryProf: factory usage counts and cascades, with flamegraphs
  • RSpecDissect: time spent in before hooks and let
  • MemoryProf: RSS, allocations and GC time per example or group
  • TPSProf: tests per second by top-level group, with a strict mode that fails the build
  • ruby-prof and stackprof integrations
  • before_all hook and let_it_be helper for data created once per group
  • AnyFixture, FactoryDefault and FactoryAllStub recipes
View 4 more
  • RSpec Stamp to tag examples automatically
  • tests sampling
  • RuboCop cops
  • RSpec and Minitest support, MRI and JRuby

Capabilities

Has an APIplan not known