Using the seed value from rake in unit and functional tests

Ruby on-RailsRakeRake Test

Ruby on-Rails Problem Overview


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?

Ruby on-Rails Solutions


Solution 1 - Ruby on-Rails

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

Solution 2 - Ruby on-Rails

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

SEED=20290 rake test

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionVirtualStaticVoidView Question on Stackoverflow
Solution 1 - Ruby on-RailsMrDanAView Answer on Stackoverflow
Solution 2 - Ruby on-RailsCarl ZulaufView Answer on Stackoverflow