我有一个Rakefile定义的代码如下:
namespace :app do |args|
desc "Run App tests from lib/app_tests/test_*.rb"
Rake::TestTask.new do |t,args|
t.name = "testApp"
t.libs << 'lib/pageobjects/app_page_objects'
t.test_files = FileList['lib/app_tests/test_*.rb']
#t.options - passing on command line see below
t.verbose = true
end
...
但是,当我运行任务时,它会将TESTOPTS args视为测试运行器想要运行的其他测试。我想要的是t.test_files中的每个测试,将3个参数传递给每个测试。我看到的主要错误是:
cannot load such file -- c:/Users/me/IdeaProjects/impl/util/PROJECT/testclient
为什么Rake将我的TESTOPTS视为t.test_files FileList对象中的附加项?根据我对JUnit的经验,这对我来说似乎不太常见。
这是控制台输出:
$ rake app:testapp TESTOPTS="testclient impdev app"
c:/Ruby22-x64/bin/ruby.exe -I"lib;lib/pageobjects/app_page_objects" "c:/Ruby22-x64/lib/ruby/2.2.0/rake/rake_test_loader.rb" "lib/app_tests/test_1.rb" "lib/app_tests/test_2.rb" testclient impdev app
Current dir is : c:/Users/me/IdeaProjects/impl/util/PROJECT
c:/Ruby22-x64/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require': cannot load such file -- c:/Users/me/IdeaProjects/impl/util/PROJECT/testclient (LoadError)
from c:/Ruby22-x64/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from c:/Ruby22-x64/lib/ruby/2.2.0/rake/rake_test_loader.rb:15:in `block in <main>'
from c:/Ruby22-x64/lib/ruby/2.2.0/rake/rake_test_loader.rb:4:in `select'
from c:/Ruby22-x64/lib/ruby/2.2.0/rake/rake_test_loader.rb:4:in `<main>'
rake aborted!
Command failed with status (1): [ruby -I"lib;lib/pageobjects/app_page_objects" "c:/Ruby22-x64/lib/ruby/2.2.0/rake/rake_test_loader.rb"
"lib/app_tests/test_browse_conditions.rb" "lib/app_tests/test_example.rb" testclient impdev app]
end
修改
我在GitHub上创建了一个可以重现问题的测试项目。只需下载项目并使用&#39; rake test&#39;运行测试。 : https://github.com/djangofan/RakeUnitTests/tree/5df4825d105251c81d425d3aef986e3f7d2f9f44
另外,我发现parallel_test(没有rake)能够按照我想要的方式传递测试参数,并使用&#39; -o&#39;论点。我只是希望我知道如何用Rake做到这一点。