Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using the seed value from rake in unit and functional tests

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?

like image 520
VirtualStaticVoid Avatar asked May 04 '11 08:05

VirtualStaticVoid


2 Answers

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

like image 99
MrDanA Avatar answered Sep 19 '22 14:09

MrDanA


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

SEED=20290 rake test 
like image 37
Carl Zulauf Avatar answered Sep 19 '22 14:09

Carl Zulauf