69

When running unit and functional tests using rake, on a rails application, I notice that there is a seed value which is specified on the command line: --seed x

$ rake test
(in /code/blah)
Loaded suite /../ruby-1.9.2-p180/gems/rake-0.8.7/lib/rake/rake_test_loader
Started
.
Finished in 0.12345 seconds.

1 tests, 1 assertions, 0 failures, 0 errors, 0 skips

Test run options: --seed 20290

I assume it is possible to use this value in the tests, but I can't figure out how. I've tried Google, Rails Guides et al. but can't seem to find the answer.

EDIT:

Could this seed value be the option that is used by Minitest to randomize the execution order of tests?

VirtualStaticVoid
  • 1,656
  • 3
  • 15
  • 21

2 Answers2

96

I found this online about MiniTest: http://www.mikeperham.com/2012/09/25/minitest-ruby-1-9s-test-framework/

Turns out, you are right. It is about randomizing the execution order of tests. You can explicitly use them like this:

rake TESTOPTS="--seed=1261"

(according to the above link).

knut
  • 27,320
  • 6
  • 84
  • 112
MrDanA
  • 11,489
  • 2
  • 36
  • 47
  • This does not work... Use the answer below for minitest – Jeff Davenport Jul 30 '19 at 19:09
  • Oh, it affects only the order of running tests... On a side note, haven't you ever run into problems with `rake TESTOPTS=...`? I just [did](https://gist.github.com/x-yuri/bc33a8bb81d1b0502a157349427c56f3). – x-yuri Jan 03 '21 at 15:41
80

The answer from MrDanA is correct. This solution also works and is slightly shorter and easier to remember.

SEED=20290 rake test
Community
  • 1
  • 1
Carl Zulauf
  • 39,378
  • 2
  • 34
  • 47