- A
- F
- P
- T
- ActiveSupport::Testing::Assertions
- ActiveSupport::Testing::ErrorReporterAssertions
- ActiveSupport::Testing::Deprecation
- ActiveSupport::Testing::ConstantStubbing
- ActiveSupport::Testing::TimeHelpers
- ActiveSupport::Testing::FileFixtures
常數
Assertion | = | Minitest::Assertion |
類別公開方法
fixture_paths 連結
傳回 ActiveRecord::FixtureSet
集合。
在您的 test_helper.rb
中必須要有 require "rails/test_help"
。
來源:在 Github 上
# File activesupport/lib/active_support/test_case.rb, line 122
fixture_paths=(fixture_paths) 連結
設定給定路徑至固定集合。
也能附加多個路徑。
ActiveSupport::TestCase.fixture_paths << "component1/test/fixtures"
在您的 test_helper.rb
中必須要有 require "rails/test_help"
。
來源:在 Github 上
# File activesupport/lib/active_support/test_case.rb, line 128
parallelize(workers: :number_of_processors, with: :processes, threshold: ActiveSupport.test_parallelization_threshold) 連結
將測試套件平行處理。
帶有 workers
參數,控制程序分岔的次數。對於每個程序,將建立一個新的資料庫並加上工作人員編號。
test-database-0
test-database-1
如果設定 ENV["PARALLEL_WORKERS"]
,將忽略工作人員參數,而改用環境變數。這很適用於 CI 環境,或是在可能需要比本地測試更多的工作人員時使用的其他環境。
如果工作人員編號設定為 1
或更少,測試將不會平行處理。
如果 workers
設定為 :number_of_processors
,工作人員編號將設定為您所在機器上的實際核心數。
預設的平行處理方式是分岔程序。如果您想改用執行緒,可以將 with: :threads
傳遞給 parallelize
方法。請注意,執行緒平行處理不會建立多個資料庫,且無法搭配系統測試使用。
parallelize(workers: :number_of_processors, with: :threads)
執行緒平行處理直接使用 minitest 的平行執行器。程序平行處理使用 Ruby DRb 伺服器。
由於平行處理有額外負擔,只有當要執行的測試數量多於 threshold
參數才會啟用平行處理。預設值為 50,而且可透過 config.active_support.test_parallelization_threshold
進行設定。
來源:顯示 | 在 Github 上
# File activesupport/lib/active_support/test_case.rb, line 81 def parallelize(workers: :number_of_processors, with: :processes, threshold: ActiveSupport.test_parallelization_threshold) workers = Concurrent.processor_count if workers == :number_of_processors workers = ENV["PARALLEL_WORKERS"].to_i if ENV["PARALLEL_WORKERS"] Minitest.parallel_executor = ActiveSupport::Testing::ParallelizeExecutor.new(size: workers, with: with, threshold: threshold) end
parallelize_setup(&block) 連結
設定平行測試的 Hook。如果有多個資料庫或者任何行為需要在程序分叉後、單元測試執行前執行,可以使用這個設定。
註:此功能無法與平行執行緒同時使用。
在 test_helper.rb
加入以下程式碼:
class ActiveSupport::TestCase
parallelize_setup do
# create databases
end
end
parallelize_teardown(&block) 連結
清理平行測試的 Hook。如果你的應用程式使用寫入或讀取資料庫,可以使用這個設定來刪除資料庫,或在測試結束前進行其他清理。這會在分叉程序結束前執行。
註:此功能無法與平行執行緒同時使用。
在 test_helper.rb
加入以下程式碼:
class ActiveSupport::TestCase
parallelize_teardown do
# drop databases
end
end
test_order() 連結
傳回測試用案例執行的順序。
ActiveSupport::TestCase.test_order # => :random
可能的數值為 :random
、:parallel
、:alpha
、:sorted
。預設值為 :random
。
test_order=(new_order) 連結
設定測試用案例執行的順序。
ActiveSupport::TestCase.test_order = :random # => :random
有效的數值為:
-
:random
(隨機執行測試) -
:parallel
(平行執行測試) -
:sorted
(按方法名稱字母順序執行測試) -
:alpha
(等於:sorted
)
實例公共方法
assert_no_match(matcher, obj, msg = nil) 連結
別名: refute_match
原始碼: GitHub
# File activesupport/lib/active_support/test_case.rb, line 233
assert_not_empty(obj, msg = nil) 連結
別名: refute_empty
原始碼: GitHub
# File activesupport/lib/active_support/test_case.rb, line 156
assert_not_equal(exp, act, msg = nil) 連結
別名: refute_equal
原始碼: GitHub
# File activesupport/lib/active_support/test_case.rb, line 167
assert_not_in_delta(exp, act, delta = 0.001, msg = nil) 連結
別名: refute_in_delta
原始碼: GitHub
# File activesupport/lib/active_support/test_case.rb, line 178
assert_not_in_epsilon(a, b, epsilon = 0.001, msg = nil) 連結
來源:on GitHub
# File activesupport/lib/active_support/test_case.rb, line 189
assert_not_includes(collection, obj, msg = nil) 連結
來源:on GitHub
# File activesupport/lib/active_support/test_case.rb, line 200
assert_not_instance_of(cls, obj, msg = nil) 連結
來源:on GitHub
# File activesupport/lib/active_support/test_case.rb, line 211
assert_not_kind_of(cls, obj, msg = nil) 連結
來源:on GitHub
# File activesupport/lib/active_support/test_case.rb, line 222
assert_not_nil(obj, msg = nil) 連結
別名:refute_nil
來源:on GitHub
# File activesupport/lib/active_support/test_case.rb, line 244
assert_not_operator(o1, op, o2 = UNDEFINED, msg = nil) 連結
來源:on GitHub
# File activesupport/lib/active_support/test_case.rb, line 255
assert_not_predicate(o1, op, msg = nil) 連結
來源:on GitHub
# File activesupport/lib/active_support/test_case.rb, line 266
assert_not_respond_to(obj, meth, msg = nil) 連結
來源:on GitHub
# File activesupport/lib/active_support/test_case.rb, line 277
assert_not_same(exp, act, msg = nil) 連結
別名:refute_same
來源:on GitHub
# File activesupport/lib/active_support/test_case.rb, line 288