Using the seed value from rake in unit and functional tests

VirtualStaticVoid picture VirtualStaticVoid · May 4, 2011 · Viewed 12.2k times · Source

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?

Answer

MrDanA picture MrDanA · Jun 22, 2011

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).