说我有一个文件,其中包含要从中运行测试的测试文件的名称,它也可以包含特定的测试名称。如果测试文件包含该特定测试,则仅从包含该测试的文件中运行该测试,然后运行其他测试文件中的所有测试。
我使用Codebuild为我们的应用程序运行测试,但是Codebuild没有提供仅运行特定测试的方法。因此,我要用自定义rake任务替换codebuild上的bin / rails测试命令。该rake任务将在我们的系统中检查包含要运行的测试列表的文件,如果找到该文件,则仅运行那些测试以及其他正常的bin / rails test
答案 0 :(得分:0)
您可以复制Rails如何定义其任务,例如test:system
here:
namespace :test do
desc "Run tests from file"
task from_file: "test:prepare" do
$: << "test"
Rails::TestUnit::Runner.rake_run(
File.read(Rails.root.join("tests_to_run.txt")).lines.map(&:chomp)
)
end
end
$ bundle exec rails test:from_file