- 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 121
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 127
parallelize(workers: :number_of_processors, with: :processes, threshold: ActiveSupport.test_parallelization_threshold) 链接
并行化测试套件。
接受一个 workers
参数,该参数控制进程被分叉的次数。对于每个进程,将创建一个新的数据库,并在其后缀中添加工作程序编号。
test-database-0
test-database-1
如果设置了ENV["PARALLEL_WORKERS"]
,则会忽略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
进行配置。
# File activesupport/lib/active_support/test_case.rb, line 80 def parallelize(workers: :number_of_processors, with: :processes, threshold: ActiveSupport.test_parallelization_threshold) workers = Concurrent.physical_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) 链接
并行测试的设置钩子。如果有多个数据库或任何需要在派生进程后但在测试运行之前执行的行为,可以使用它。
注意:此功能在使用线程并行化时不可用。
在您的test_helper.rb
中添加以下内容
class ActiveSupport::TestCase
parallelize_setup do
# create databases
end
end
parallelize_teardown(&block) 链接
并行测试的清理钩子。这可用于在测试完成后删除数据库(如果您的应用程序使用多个读写数据库)或进行其他清理。这在派生进程关闭之前运行。
注意:此功能在使用线程并行化时不可用。
在您的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
。
来源:显示 | GitHub 上查看
# File activesupport/lib/active_support/test_case.rb, line 43 def test_order ActiveSupport.test_order ||= :random end
test_order=(new_order) 链接
设置测试用例的执行顺序。
ActiveSupport::TestCase.test_order = :random # => :random
有效取值包括
-
:random
(以随机顺序执行测试) -
:parallel
(以并行方式执行测试) -
:sorted
(按方法名称的字母顺序执行测试) -
:alpha
(等同于:sorted
)
来源:显示 | GitHub 上查看
# File activesupport/lib/active_support/test_case.rb, line 33 def test_order=(new_order) ActiveSupport.test_order = new_order end
实例公共方法
assert_no_match(matcher, obj, msg = nil) 链接
别名:refute_match
来源:GitHub 上查看
# File activesupport/lib/active_support/test_case.rb, line 231
assert_not_empty(obj, msg = nil) 链接
别名:refute_empty
来源:GitHub 上查看
# File activesupport/lib/active_support/test_case.rb, line 154
assert_not_equal(exp, act, msg = nil) 链接
别名:refute_equal
来源:GitHub 上查看
# File activesupport/lib/active_support/test_case.rb, line 165
assert_not_in_delta(exp, act, delta = 0.001, msg = nil) 链接
来源:GitHub 上查看
# File activesupport/lib/active_support/test_case.rb, line 176
assert_not_in_epsilon(a, b, epsilon = 0.001, msg = nil) 链接
来源:GitHub 上查看
# File activesupport/lib/active_support/test_case.rb, line 187
assert_not_includes(collection, obj, msg = nil) 链接
来源:GitHub 上
# File activesupport/lib/active_support/test_case.rb, line 198
assert_not_instance_of(cls, obj, msg = nil) 链接
来源:GitHub 上
# File activesupport/lib/active_support/test_case.rb, line 209
assert_not_kind_of(cls, obj, msg = nil) 链接
来源:GitHub 上
# File activesupport/lib/active_support/test_case.rb, line 220
assert_not_nil(obj, msg = nil) 链接
别名:refute_nil
来源:GitHub 上
# File activesupport/lib/active_support/test_case.rb, line 242
assert_not_operator(o1, op, o2 = UNDEFINED, msg = nil) 链接
来源:GitHub 上
# File activesupport/lib/active_support/test_case.rb, line 253
assert_not_predicate(o1, op, msg = nil) 链接
来源:GitHub 上
# File activesupport/lib/active_support/test_case.rb, line 264
assert_not_respond_to(obj, meth, msg = nil) 链接
来源:GitHub 上
# File activesupport/lib/active_support/test_case.rb, line 275
assert_not_same(exp, act, msg = nil) 链接
别名:refute_same
来源:GitHub 上
# File activesupport/lib/active_support/test_case.rb, line 286