显示每个 rspec 示例的运行时 [英] Show runtime for each rspec example

查看:41
本文介绍了显示每个 rspec 示例的运行时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前我正在运行超过 1000 个示例,需要很长时间才能完成(超过 20 分钟!!!).

currently I'm running more than 1k examples and it's taking a long time to complete (more than 20 minutes!!!).

我想确定哪些示例需要更多时间才能完成,有没有办法运行 rspec 并返回每个示例完成(单独)所需的时间?我正在使用 rspec 1.3.0rspec-rails 1.2.3

I'd like to identify which examples are the ones taking more time to complete, is there any way to run rspec and return the time each example takes to complete(individually)? I'm using rspec 1.3.0 and rspec-rails 1.2.3

推荐答案

您可以使用分析来列出 10 个最慢的示例:

You can use profiling to list your 10 slowest examples:

spec -p spec/*/*_spec.rb --colour --format profile

如果您在特定的测试套件上运行它,您可以从较小的示例子集中获得 10 个最慢的示例:

If you run this on a specific test suite you can get the 10 slowest examples from a smaller subset of examples:

spec -p spec/models/user_spec.rb --format profile

较新版本的 Rspec

对于较新版本的 rspec,您应该使用 --profile 选项:

rspec spec/ --profile         | (shows the 10 slowest examples)
rspec spec/ --profile 2       | (shows the 2  slowest examples)

这篇关于显示每个 rspec 示例的运行时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆