Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/schwern/test-random
Make testing random things a bit more deterministic
https://github.com/schwern/test-random
Last synced: about 1 month ago
JSON representation
Make testing random things a bit more deterministic
- Host: GitHub
- URL: https://github.com/schwern/test-random
- Owner: schwern
- License: other
- Created: 2010-01-20T01:12:31.000Z (about 15 years ago)
- Default Branch: master
- Last Pushed: 2013-04-28T02:53:23.000Z (over 11 years ago)
- Last Synced: 2024-10-29T20:08:28.345Z (3 months ago)
- Language: Perl
- Homepage: http://search.cpan.org/dist/Test-Random
- Size: 121 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README
- Changelog: Changes
- License: LICENSE
Awesome Lists containing this project
README
NAME
Test::Random - Make testing random functions deterministicSYNOPSIS
use Test::Random;... test as normal ...
DESCRIPTION
This is a testing module to make testing random things a bit more
deterministic.Controlling randomness
Its main function is to allow you to repeat a failing test in the same
way it ran before, even if it contained random elements. Test::Random
will output the seed used by the random number generator. You can then
use this seed to repeat the last test with exactly the same random
elements.You can control the random seed used by Test::Random by setting the
"TEST_RANDOM_SEED" environment variable. This is handy to make test runs
repeatable.TEST_RANDOM_SEED=12345 perl -Ilib t/some_test.t
Test::Random will output the seed used at the end of each test run. If
the test failed it will be visible to the user (ie. on STDERR) otherwise
it will be a TAP comment and only visible if the test is run verbosely.If having new data every run is too chaotic for you, you can set
TEST_RANDOM_SEED to something which will remain fixed during a
development session. Perhaps the PID of your shell or your uid or the
date (20090704, for example).EXAMPLE
When you run a test with Test::Random you will see something like this:perl some_test.t
1..3
ok 1
ok 2
ok 3
# TEST_RANDOM_SEED=20891494266If you wish to repeat the circumstances of that test, with the same
randomly generated data, you can run it again with the
" environment variable set to the given seed.TEST_RANDOM_SEED=20891494266 perl some_test.t
1..3
ok 1
ok 2
ok 3
# TEST_RANDOM_SEED=20891494266See your shell and operating system's documentation for details on how
to set environment variables.CAVEATS
If something in your code calls srand() all bets are off.SEE ALSO
Test::RandomResults, Test::Sims, Data::Random, Data::Generate