Skip to content

Commit bc36cac

Browse files
authored
Detect failing standalone tests (fastlane#22273)
* Detect failing standalone tests * Add the RPSEC_ARGS to allow the user to add more arguments * Update doc * Typo
1 parent 40c3e60 commit bc36cac

File tree

2 files changed

+72
-2
lines changed

2 files changed

+72
-2
lines changed

Rakefile

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,12 @@ end
1616
task(:test_all) do
1717
formatter = "--format progress"
1818
formatter += " -r rspec_junit_formatter --format RspecJunitFormatter -o #{ENV['CIRCLE_TEST_REPORTS']}/rspec/fastlane-junit-results.xml" if ENV["CIRCLE_TEST_REPORTS"]
19-
command = "rspec --pattern ./**/*_spec.rb #{formatter}"
19+
command = "rspec --pattern ./**/*_spec.rb #{formatter} #{ENV['RSPEC_ARGS']}"
2020

21+
run_rspec(command)
22+
end
23+
24+
def run_rspec(command)
2125
# To move Ruby 3.0 or next major version migration going forward, we want to keep monitoring deprecation warnings
2226
if Gem.win_platform?
2327
# Windows would not work with /bin/bash so skip collecting warnings
@@ -30,6 +34,27 @@ task(:test_all) do
3034
end
3135
end
3236

37+
# run, displays and saves the list of tests that do not work standalone
38+
task(:test_all_individually) do
39+
files = Dir.glob("./**/*_spec.rb")
40+
41+
failed = files.select do |file|
42+
formatter = "--format progress"
43+
command = "rspec #{formatter} #{ENV['RSPEC_ARGS']} #{file}"
44+
run_rspec(command)
45+
false
46+
rescue => _
47+
true
48+
end
49+
50+
unless failed.empty?
51+
puts("Individual tests failing: #{failed.join(' ')}")
52+
file = "failed_tests"
53+
File.write(file, failed.join("\n"))
54+
raise "Some tests are failing when ran on their own. See #{file}"
55+
end
56+
end
57+
3358
# Overwrite the default rake task
3459
# since we use fastlane to deploy fastlane
3560
task(:push) do

Testing.md

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,24 @@ You can also run those steps independently or on a more fine-grained way.
1414

1515
### Automated tests
1616

17-
Make sure to run the automated tests using `bundle exec` to ensure you’re running the correct version of `rspec` and `rubocop`
17+
Make sure to run the automated tests using `bundle exec` to ensure you’re running the correct version of `rspec` and `rubocop`.
1818

1919
#### All unit tests
2020

2121
First, navigate into the root of the _fastlane_ project and run all unit tests using
2222

23+
```
24+
bundle exec rake test_all
25+
```
26+
27+
You can also invoke rspec directly
28+
2329
```
2430
bundle exec rspec
2531
```
2632

33+
The test execution sends all standard output to a random temporary file. Prefix the command line with `DEBUG= ` to print out the output instead. E.g. `DEBUG= bundle exec rspec`
34+
2735
#### Unit tests for one specific tool
2836

2937
If you want to run tests only for one tool, use
@@ -54,6 +62,43 @@ The number is the line number of the unit test (`it ... do`) or unit test group
5462

5563
Instead of using the line number you can also use a filter with the `it "something", now: true` notation and then use `bundle exec rspec -t now` to run this tagged test. (Note that `now` can be any random string of your choice.)
5664

65+
#### Ensuring all tests run independently
66+
67+
If you want to check if all the tests in the test suite can be run independently, use
68+
69+
```
70+
bundle exec rake test_all_individually
71+
```
72+
73+
#### Troubleshoot flickering tests
74+
75+
If your tests fail randomly, pass extra arguments to `test_all` and `test_all_individually` using the environment variable `RSPEC_ARGS` to isolate the test failures and reproduce them.
76+
77+
Here are some examples.
78+
79+
Randomize the order of tests for the full suite:
80+
```
81+
RSPEC_ARGS="--order rand" bundle exec rake test_all
82+
```
83+
84+
Pass a given seed to the full test suite:
85+
```
86+
RSPEC_ARGS="--seed 1234" bundle exec rake test_all
87+
```
88+
89+
Run each test file independently and randomize within each run:
90+
```
91+
RSPEC_ARGS="--bisect random" bundle exec rake test_all_individually
92+
```
93+
94+
Run the specific tests in bisect mode with a given seed:
95+
```
96+
bundle exec rspec --seed 1234 bisect your/list/of/tests.rb
97+
```
98+
99+
For more information, see [rspec command line documentation](https://rspec.info/features/3-13/rspec-core/command-line/)
100+
101+
57102
### Code style
58103

59104
To verify and auto-fix the code style

0 commit comments

Comments
 (0)