在 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)
可以衡量覆盖率。