1
votes

Say I have a file containing name of test files to run tests from and It can contain specific test names too. If test file contains that specific test, run only that test from the file containing the test and run all tests from other test files.

I use Codebuild to run tests for our application but Codebuild does not provide a way to run only specific tests. So I am replacing bin/rails test command on codebuild with our custom rake task. That rake task will check for a file in our system containing list of tests to run and If it finds the file it run only those tests other normal bin/rails test

1
At least in RSPEC you can define groups of tests, which you can then call when running bundle exec rspec, I'm sure Minitest has comparable functionality.bo-oz
It seems there's a separate gem that allows you to set tags... this would enable you to run only selected tests. I think this is a more perferable approach to using lists of tests in a file: stackoverflow.com/questions/51913064/…bo-oz
I think a file is more preferable approach as in order to run all tests all we have to do is make file empty. Searching and removing tags will add extra effort when we want to run all tests.Mohsin Sethi
Well, you could always create a bash script that loops through the file and runs the minitests for the entries.bo-oz
That will run multiple RAILS_ENV=test rails test which in result will have multiple outputs whereas I want a solution to run just 1 RAILS_ENV=test rails test so that I have 1 standard minitest output at the end e.g. passed: 123, failed: 123 and so onMohsin Sethi

1 Answers

0
votes

You could copy how rails is already defining their tasks like 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