如何找到哪个 rspec 测试需要这么长时间 [英] How to find which rspec test is taking so long

查看:31
本文介绍了如何找到哪个 rspec 测试需要这么长时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们的一个(或几个)测试需要很长时间,我们希望对其进行优化.

One (or a couple) of our tests are taking forever and we'd like to optimize them.

我们说要进行 1000 次测试,所以对我来说运行每个文件是不切实际的.

We have say 1000 tests so it's impractical for me to go through run each file.

有没有一种简单的方法可以找到慢的?

Is there an easy to way to find the slow ones?

这是 rspec 1.3

This is rspec 1.3

推荐答案

在 RSpec 2 和 3 中,您可以使用 --profile 标志或添加 --profile到您的 .rspec 文件.这将跟踪前 10 个最慢的示例.

In RSpec 2 and 3, you can use the --profile flag or add --profile to your .rspec file. This will track the top 10 slowest examples.

对于 RSpec 1,您可以使用 --format ospec 命令.它显示了一个基于文本的进度条,其中包含 10 个最慢示例的分析.有关更多详细信息请参阅此.

For RSpec 1, you can use --format o with spec command. It shows a text-based progress bar with profiling of 10 slowest examples. For more details see this.

rspec --profile -- path/to/file/spec.rb

这篇关于如何找到哪个 rspec 测试需要这么长时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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