ruby-on-rails - Rails 中的测试覆盖率

标签 ruby-on-rails ruby minitest

<分区>

有没有什么方法可以用来找出 Ruby on Rails 应用程序的代码覆盖率?

最佳答案

在大多数情况下,Rails 的最佳代码覆盖解决方案是 SimpleCov。

Rcov 现在已经过时了,因为它不能很好地与 Ruby 1.9 及更高版本一起工作。

此外,如果您对突变测试感兴趣,您应该看看 mutant gem .

The idea is that if code can be changed and your tests do not notice, then either that code isn't being covered or it does not have a speced side effect.

目前它只支持 RSpec。 Minitest 集成仍在进行中。

这是一个很棒的article关于它。 基本上,Rcov 和 SimpleCov 只检查线路覆盖率。

Mutation testing takes your code and your tests. It parses the code to the Abstract Syntax Tree. It changes the nodes of the tree (mutates). It does it in memory. As a result we now have a mutant - a mutated version of your code... The idea here is that the tests should kill the mutant. Killing the mutant happens when tests fail for a mutated code. Killing all mutants means that you have a 100% test coverage. It means that you have tests for all of your code details. This means you can safely refactor and your tests are really covering you.

关于ruby-on-rails - Rails 中的测试覆盖率,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42630828/

相关文章:

ruby-on-rails - 如何将 Ruby On Rails 网站移动到新服务器

ruby-on-rails - CarrierWave 并根据其内容更正文件扩展名

ruby-on-rails - 为什么我的 ruby​​ 测试找不到访问?

ruby-on-rails - { :null=>false} in my migration: why? 的未定义方法 `to_sym'

javascript - Rails 应用程序元素在 classie.js 中为空

类名中的 Ruby 插值

ruby-on-rails - 如何拥有线程安全的 Rails 初始化器?

ruby-on-rails - 如何将 gem 'minitest' 添加到我的测试助手?

ruby-on-rails - 测试时,每次在 Rails 3.2 中调整 Javascript 文件时都必须预编译 Assets 吗?

ruby-on-rails - Rails - 保存 Ransack 查询以供以后使用