ruby-on-railsruby-on-rails-5ruby-on-rails-6

How to run all tests, including system tests, at once in Rails 6?


To run tests in Rails 5+, I'd do two separate commands:

$ rails test
# Running:
........    
$ rails test:system
# Running:
........

How can I run both sets of tests from a single command line request?


Solution

  • To run all tests, you can list them all:

    $ rails test:system test:models test:mailers ....
    

    And you'll get the correct summarized totals:

    Finished in 15.824006s, 1.8327 runs/s, 4.2973 assertions/s.
    30 runs, 69 assertions, 0 failures, 0 errors, 0 skips
    

    The shortcut is to do:

    $ rails test:system test
    Finished in 14.427353s, 2.0794 runs/s, 4.7826 assertions/s.
    30 runs, 69 assertions, 0 failures, 0 errors, 0 skips
    

    Which will do all of your tests since "test" includes all tests, except 'test:system'. One caveat is that if you list 'test' first, it won't run your system tests.

    So, this will only run 'test', and not 'test:system'

    $ rails test test:system
    Finished in 0.736070s, 13.5857 runs/s, 23.0956 assertions/s.
    10 runs, 17 assertions, 0 failures, 0 errors, 0 skips