Sort minitest tests by duration
TLDR; sort -t = -k 2 -g
Sometimes it's interesting to know which tests are fast and which are not.
Minitest allows you to display elapsed time of each test by passing -v
flag.
Minitest's output
The output invoked with -v
of minitest looks like:
...
CookiesTest#test_encrypted_cookie_using_marshal_serializer = 0.57 s = .
CookiesTest#test_encrypted_cookie_using_custom_digest = 0.58 s = .
CookiesTest#test_encrypted_cookie_using_default_serializer = 0.58 s = .
CookiesTest#test_encrypted_cookie_using_json_serializer = 0.58 s = .
...
The command to sort this output by its duration is
sort -t = -k 2 -g
Examples
rake
rake test TESTOPTS=-v | sort -t = -k 2 -g
ruby -Ilib:test
ruby -Ilib:test ... -v | sort -t = -k 2 -g
As a bash function
I've aliased the sorting function to mt_sort
so I can easily do
rake test TESTOPTS=-v | mt_sort
Written by Peter Suschlik
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Ruby
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#