Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Find an easy way to list the slower tests #69

Open
octopusinvitro opened this issue Feb 22, 2017 · 1 comment
Open

Find an easy way to list the slower tests #69

octopusinvitro opened this issue Feb 22, 2017 · 1 comment

Comments

@octopusinvitro
Copy link
Contributor

octopusinvitro commented Feb 22, 2017

At the moment we can do:

bundle exec rake TESTOPTS='-v'

to print how much time each test takes to run. However it would be nice to be able to see, say, the top 20 slowest tests.

I found some ways of doing it, but I don't quite like them:

  • Monkey-patching Minitest to create a custom reporter... NOPE. Also, seems like the only way to do this is creating a library out of it, rather than adding some simple code in your test_helper, for example. I tried this and couldn't make it work, but I didn't spend more than one hour on it.
  • Installing the minitest-reporters gem, BUT dependencies!
  • Changing all our tests from the it syntax to the test_name_of_test syntax so that we can do bundle exec rake TESTOPTS='--verbose' | sort -t = -k 2 -g on the terminal. NOPE.
  • output to a file and manipulate its contents in pry, the poor man approach I'm following.
$ bundle exec rake TESTOPTS='-v' > foo
$ pry
> x = File.readlines('./foo')
> z = x.sort_by { |y| y.split('=')[1].to_f }.reverse.map { |y| y.strip }.take(20)

^^^ 😱 😱 😱 😱

I'm sure there should be an easy way to do this.

BTW, the slowest tests are of course the integration tests! (i.e., the web tests). At the moment of writing this I get:

"Federal Constituency Place Page::social block#test_0002_links to facebook share = 0.29 s = .",
"List of Representatives::person item::when person does not have an image#test_0001_shows a picture anyway (empty avatar) = 0.18 s = .",
"List of Representatives::person item#test_0001_links to the person page = 0.17 s = .",
"List of Representatives::person item#test_0004_links to area page = 0.15 s = .",
"List of Representatives::person item#test_0007_displays party name = 0.15 s = .",
"List of Representatives::person list#test_0001_lists all representatives = 0.14 s = .",
"List of Representatives::person item::when person has an image#test_0001_points to the right path = 0.14 s = .",
"Posts Page#test_0002_shows all posts = 0.13 s = .",
"Posts Page#test_0001_shows the title = 0.13 s = .",
"Posts Page::when displaying a post#test_0004_displays post excerpt = 0.12 s = .",
"Posts Page::when displaying a post#test_0003_displays post date = 0.12 s = .",
"List of Representatives::person item#test_0003_shows right area type name = 0.12 s = .",
"List of Representatives::person item::when person has an image#test_0003_has the name as alternative text = 0.12 s = .",
"Posts Page::when displaying a post#test_0001_links to post url = 0.11 s = .",
"List of Representatives::person item#test_0005_displays area name = 0.11 s = .",
"Federal Constituency Place Page::person item#test_0007_links to the person area = 0.10 s = .",
"Posts Page::when displaying a post#test_0002_displays post title = 0.10 s = .",
"Page::Place#test_0008_has all the people for that place = 0.10 s = .",
"List of Representatives::person item::when person has an image#test_0002_has an srcset = 0.10 s = .",
"List of Representatives#test_0001_shows the title = 0.10 s = ."
@mhl
Copy link
Contributor

mhl commented Mar 27, 2017

Timebox to 1 day

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

No branches or pull requests

2 participants