Rails 5.1 run system tests and normal tests with one command
Asked Answered
F

7

24

In Rails 5.1, you can do bin/rails test to run normal tests, and bin/rails test:system. What is the Rails sanctioned way of running both at the same time?

Flavoprotein answered 21/8, 2017 at 13:40 Comment(2)
I am not sure but can you try using bin/rails test test:system? It should load Rails' env and your app only once.Rickettsia
Sadly didn't work; just ran the normal suite, not system tests.Flavoprotein
U
32

bin/rails test:system test

Specifying test:system before test will run both system and ordinary tests. The opposite order will only run the ordinary tests however.

Undulation answered 14/4, 2018 at 9:37 Comment(1)
Thank you for this answer. I've been using simplecov to verify my test coverage and this command really helps. rails test gets me 54.96%. 'rails test:system' gets me 42.82%, but rails test:system test runs both and gets me 78.64% coverage, so I can see the overlap.Nickles
P
17

rails test:all (Rails 6.1+)

Rails 6.1 introduces a new command - rails test:all.

It runs all test files in the test directory, including system tests.

Here is a link to PR. And also a link to the docs (please, scroll down to yellow box).

Pedaias answered 8/6, 2020 at 18:17 Comment(0)
A
4

In case anyone else is looking for the answer:

bin/rails test test/*

Amblyoscope answered 13/2, 2018 at 2:27 Comment(0)
C
2

If it is your intention to run it using just $ rake or $rake test you can add into your Rakefile:

task test: 'test:system'

This will makes 'test:system' a "prerequisites" for "test" task

Coenesthesia answered 18/4, 2018 at 23:22 Comment(0)
K
1

At least from the official rails guide, it seems there is no way of doing it:

By default, running bin/rails test won't run your system tests. Make sure to run bin/rails test:system to actually run them.

Ref: rails guide

Krouse answered 23/10, 2017 at 23:59 Comment(0)
K
0

You can also add this snippet in your lib/tasks folder, that will give you the option to do rake test:all

namespace :test do desc "Run both regular tests and system tests" task :all => 'test' do Minitest.after_run {system('rake test:system')} end end

Karena answered 1/11, 2018 at 10:53 Comment(0)
I
0

Summary of all the answers for easy reference:

System tests Only

bin/rails test:system

Ordinary tests Only

bin/rails test .

ALL tests

bin/rails test:all

Investment answered 22/12, 2020 at 2:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.