Ruby tests profiling and optimization toolbox
TestProf is a collection of different tools to analyze your test suite performance.
Why does test suite performance matter? First of all, testing is a part of a developer's feedback loop (see @searls talk) and, secondly, it is a part of a deployment cycle.
Simply speaking, slow tests waste your time making you less productive.
TestProf toolbox aims to help you identify bottlenecks in your test suite. It contains:
-
Plug'n'Play integration for general Ruby profilers (
ruby-prof
,stackprof
) -
Factories usage analyzers and profilers
-
ActiveSupport-backed profilers
-
RSpec and minitest helpers to write faster tests
-
RuboCop cops
-
etc.
- Discourse reduced ~27% of their test suite time
- Gitlab reduced 39% of their API tests time
- CodeTriage
- Dev.to
- Open Project
- ...and others
-
Rails Testing on Rocket Fuel: How we made our tests 5x faster
-
Paris.rb, 2018, "99 Problems of Slow Tests" talk [video, slides]
-
BalkanRuby, 2018, "Take your slow tests to the doctor" talk [video], slides]
-
RailsClub, Moscow, 2017, "Faster Tests" talk [video (RU), slides]
Add test-prof
gem to your application:
group :test do
gem "test-prof", "~> 1.0"
end
And that's it)
Supported Ruby versions:
-
Ruby (MRI) >= 2.5.0 (NOTE: for Ruby 2.2 use TestProf < 0.7.0, Ruby 2.3 use TestProf ~> 0.7.0, Ruby 2.4 use TestProf <0.12.0)
-
JRuby >= 9.1.0.0 (NOTE: refinements-dependent features might require 9.2.7+)
Supported RSpec version (for RSpec features only): >= 3.5.0 (for older RSpec version use TestProf < 0.8.0).
Supported Rails version (for Rails features only): >= 5.2.0 (for older Rails versions use TestProf < 1.0).
When you lint your RSpec spec files with rubocop-rspec
, it will fail to properly detect RSpec constructs that TestProf defines, let_it_be
and before_all
.
Make sure to use rubocop-rspec
2.0 or newer and add the following to your .rubocop.yml
:
inherit_gem:
test-prof: config/rubocop-rspec.yml
-
Event Profiler (e.g. ActiveSupport notifications)
We also want to share some small code tricks which can help you to improve your test suite performance and efficiency:
Have an idea? Propose a feature request!
Already using TestProf? Share your story!
The gem is available as open source under the terms of the MIT License.