If you re-write your code like this:

# Dyn.pm package Dyn; use strict; use warnings; sub _max { 10 } sub _rand { rand(shift) } sub _range { my $max = _max(); my $rand_max = _rand($max); return (0..int($rand_max)); } sub get_list { my @arr = (); push @arr, $_ for _range(); return @arr; } 1; __END__
Then you can test get_list() without a random number of tests, like this:

#!/usr/bin/perl use Test::More tests => 10; use Dyn; use Test::Resub qw(resub); # _max { is( Dyn::_max, 10, 'Got expected max' ); } # _rand { my $max = 1045; srand($$); my $dyn_rand = Dyn::_rand($max); srand($$); my $core_rand = CORE::rand($max); is( $dyn_rand, $core_rand, 'We wrap CORE::rand' ); } # _range runs from 0.._max, returning only integers { my $max = 0; my $rs_max = resub 'Dyn::_max', sub { $max }; my $rs_rand = resub 'Dyn::_rand', sub { return shift }, capture => 1 +; is_deeply( [Dyn::_range], [0] ); is_deeply( $rs_rand->args, [[$max]] ); $max = 1.2; $rs_rand->reset; is_deeply( [Dyn::_range], [0, 1] ); is_deeply( $rs_rand->args, [[$max]] ); $max = 7.4; $rs_rand->reset; is_deeply( [Dyn::_range], [0..7] ); is_deeply( $rs_rand->args, [[$max]] ); } # get_list is our interface to _range { my @range; my $rs_range = resub 'Dyn::_range', sub { @range }; is_deeply( [Dyn::get_list], [] ); @range = ('a'..'f'); is_deeply( [Dyn::get_list], [qw(a b c d e f)] ); } __END__
--Belden

In reply to Re: Replace 'no_plan' with fixed number using Test::More when output is random by belden
in thread Replace 'no_plan' with fixed number using Test::More when output is random by andreas1234567

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.