什么构成了simplecov gem的Ruby覆盖率测量



在Mac OSX上运行simplecov时,所产生的覆盖范围没有什么意义。

如果运行以下测试:

rails test test/models/channel_test.rb
> 4 runs, 4 assertions, 0 failures, 0 errors, 0 skips
> Coverage report generated for Minitest to /Volumes/[...]/coverage. 0 / 0 LOC (100.0%) covered.

然而,当运行rails test test/models时,图形输出指示test/models/channel_test.rb

require "test_helper" 
class ChannelTest < ActiveSupport::TestCase 
test "invalid if name not defined" do  
channel = Channel.new(priority: 1, unit_cost: 1, daily_limit: 9999) 
assert_not channel.valid?  
assert_not channel.save, "Saved the channel without a name"
end   

更新我认为可能是所选的测试语法存在缺陷-我添加了一个补充测试,结果仍然报告
型号3 relevant lines. 0 lines covered and 3 lines missed.

class Channel < ApplicationRecord # red
validates :name, presence: true # red
end # red

因此,测试通过了,但覆盖率结果令人困惑:

a( 作为独立测试,覆盖率计数为0/0,而测试通过

b( 通过(?(测试,什么构成miss或相反的coverage

test_helper.rb

require 'simplecov'
SimpleCov.start
ENV['RAILS_ENV'] ||= 'test'
require_relative "../config/environment"
require "rails/test_help"
require 'webmock/minitest'

class ActiveSupport::TestCase
parallelize(workers: :number_of_processors)

fixtures :all
def log_in_as(user, shop)
post user_session_url, params: { user_id: user.id, active_shop_id: @site.shop_id }
end
end

更新2根据@BroiSatse的建议,注释掉parallelize(workers: :number_of_processors)允许测量覆盖范围。

谢谢,这个问题也是我的问题。所有这些都归功于BroiSatse的评论。

我在test_helper.rb中添加了以下几行,它保持了并行测试的速度优势,而不是简单地注释掉这一行。它基于BroiSatse评论中的链接:

# Run tests in parallel with specified workers
parallelize(workers: :number_of_processors)
#combine SimpleCov results to accurately get results from parallelized tests
parallelize_setup do |worker|
SimpleCov.command_name "#{SimpleCov.command_name}-#{worker}"
end
parallelize_teardown do |worker|
SimpleCov.result
end 

在此之后,SimpleCov";改进的";从3.8%到90%以上。

相关内容

  • 没有找到相关文章

最新更新