Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

How to test less with Test::More?

by johnnywang (Priest)
on Aug 18, 2004 at 20:46 UTC ( #384101=perlquestion: print w/replies, xml ) Need Help??

johnnywang has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I use Test::More for most of my tests. It works very well. In a typical case, I'll have many, say 100, test cases in a file:
use Test::More; ok($yes, "test ..."); is($this,$that, "test ..."); # many of these ....
Now typically when I change some code, a few tests will fail. Since running all tests can take some time, I'd like to only run the failed tests when I'm trying to fix them. So I found myself constantly commenting out test cases(Test::More does allow SKIP, but that's also pretty tedious). What I'd like is something like pass a list of test numbers to the script to instruct it to only run those tests, is there some good way to do that? Thanks.

Replies are listed 'Best First'.
•Re: How to do less tests with Test::More?
by merlyn (Sage) on Aug 18, 2004 at 20:50 UTC
    If running some subset of the tests is independent of others, you might just move those into separate files. That'll be easier for maintenance in the long run as well. Also, your bug reports will make more sense ("05-bigblobs.t failed").

    -- Randal L. Schwartz, Perl hacker
    Be sure to read my standard disclaimer if this is a reply.

Re: How to test less with Test::More?
by McMahon (Chaplain) on Aug 18, 2004 at 21:49 UTC
    I'm not much of a unit tester, but your problem has been addressed at the system level in a number of ways.

    Googling data-driven test might give you some good ideas about how to implement this. Typically the test framework (whatever it is) reads in a set of test-case identifiers and/or data for particular tests for a particular test run. A database, delimited file, or spreadsheet can hold the data that drives the tests.
Re: How to test less with Test::More?
by eserte (Deacon) on Aug 19, 2004 at 09:09 UTC
    You can do the following:
    • Just define a goto label just before the test you want to run
    • Add option handling to your test script, e.g.
      use Getopt::Long; GetOptions("fast" => \$do_fast_test) or die;
    • After test initialization code, add
      goto FAST_TEST_LABEL if $do_fast_test
    • And call the test with perl -Mblib t/testfile.t -fast
    If you have planned the number of tests, then you will get an error that too less tests were run (of course), but you can just ignore this or use no_plan.
      I think that it would make more sense to use a lookup table. Then the test script could execute all tests in a predefined order by default but allow the use of a command line option to run a specific test or set of tests. (And it wouldn't have to use a BASIC-style goto.)
        Too complicated. I need this feature only for quick'n'dirty debugging.
Re: How to test less with Test::More?
by dragonchild (Archbishop) on Aug 19, 2004 at 13:09 UTC
    What if you break a test you're skipping while you fix a test that's failing because you changed something?

    Ideally, I'd look at speeding up the tests. Preferably, unit tests shouldn't take more than 3-5 minutes to run, because you have mocked everything that could take a bunch of time.

    ------
    We are the carpenters and bricklayers of the Information Age.

    Then there are Damian modules.... *sigh* ... that's not about being less-lazy -- that's about being on some really good drugs -- you know, there is no spoon. - flyingmoose

    I shouldn't have to say this, but any code, unless otherwise stated, is untested

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://384101]
Approved by Ovid
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (4)
As of 2019-05-26 01:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you enjoy 3D movies?



    Results (152 votes). Check out past polls.

    Notices?
    • (Sep 10, 2018 at 22:53 UTC) Welcome new users!