对于类或系统范围的某些Rails测试,我需要一个安装和拆卸方法,但我只找到了一种方法来定义在每个测试级别上工作的常规安装/拆卸。
例如:
class ActiveSupport::TestCase
setup do
puts "Setting up"
end
teardown do
puts "tearing down"
end
end将为每个测试用例执行输出,但我希望如下所示:
class ActiveSupport::TestCase
setup_fixture do
puts "Setting up"
end
teardown_fixture do
puts "tearing down"
end
end它将在所有测试方法之前执行安装_,然后在所有测试方法之后执行拆卸_。
有没有这样的机制?如果没有,是否有一个简单的方法来修补这个机制?
发布于 2009-06-07 14:56:47
有几个流行的测试框架构建在Test::Unit之上并提供这种行为:
RSpec
describe "A Widget" do
before(:all) do
# stuff that gets run once at startup
end
before(:each) do
# stuff that gets run before each test
end
after(:each) do
# stuff that gets run after each test
end
after(:all) do
# stuff that gets run once at teardown
end
end测试/规格
context "A Widget" do
# same syntax as RSpec for before(:all), before(:each), &c.
endhttps://stackoverflow.com/questions/958669
复制相似问题