Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Run certain tests automatically using Test::Class

by moez507 (Novice)
on Apr 02, 2014 at 15:15 UTC ( #1080790=perlquestion: print w/ replies, xml ) Need Help??
moez507 has asked for the wisdom of the Perl Monks concerning the following question:

Hello Monks!
I am writing some automated regression tests with Test::Class. Before each test , I wish to check if the test is running on production. If yes, to stop the test.

However, I do not wish to depend on the programmer to remember to add this test in. Is there some way to tell each test to run this as a setup , without having to remember to code this piece in for each time a new test is written ?

I tried creating a base class and having all my tests inherit from the same. However, the tests in the base class are executing last when I want them to execute first!

Thanks,
Moez.

Comment on Run certain tests automatically using Test::Class
Re: Run certain tests automatically using Test::Class
by MidLifeXis (Prior) on Apr 02, 2014 at 18:33 UTC

    See setup and startup tests in the documentation. Also see the RUNNING ORDER OF METHODS section in the same documentation.

    --MidLifeXis

Re: Run certain tests automatically using Test::Class
by stonecolddevin (Vicar) on Apr 02, 2014 at 18:35 UTC

    Also, check out http://travis-ci.org. The free plan is quite useful for even fairly large projects.

    Three thousand years of beautiful tradition, from Moses to Sandy Koufax, you're god damn right I'm living in the fucking past

Re: Run certain tests automatically using Test::Class
by marinersk (Chaplain) on Apr 02, 2014 at 21:38 UTC

    Would it not be simpler to simply set an environment variable in the test environment, and let its absence serve as a flag to the tests themselves to voluntarily exit?

    Simply make sure every test method first does this -- or calls a method designed to do this -- and the tests will govern themselves.

    #!/usr/bin/perl use strict; use warnings; my $TestFlag = $ENV{'TEST_ENVIRONMENT'}; if (!defined $TestFlag) { $TestFlag = ''; } if ($TestFlag =~ /TRUE/i) { print "I'm running tests! I'm running tests!\n"; } else { print "This does not appear to be a test environment. Skipping te +sts.\n"; } exit; __END__ S:\Steve\Dev\PerlMonks\P-2014-04-02@1516-Self-Governing-Tests>set TEST +_ENVIRONMENT=TRUE S:\Steve\Dev\PerlMonks\P-2014-04-02@1516-Self-Governing-Tests>perl may +betest.pl I'm running tests! I'm running tests! S:\Steve\Dev\PerlMonks\P-2014-04-02@1516-Self-Governing-Tests>set TEST +_ENVIRONMENT= S:\Steve\Dev\PerlMonks\P-2014-04-02@1516-Self-Governing-Tests>perl may +betest.pl This does not appear to be a test environment. Skipping tests. S:\Steve\Dev\PerlMonks\P-2014-04-02@1516-Self-Governing-Tests>
      Thank You ! Its a very good idea.

      However, I was looking for some sort of template system , or some way that the 'test' runs automatically. Such that the programmer does not have to remember to add it in for each test.

      Perhaps , its a tall order?

      Thanks,
      Moez.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (9)
As of 2014-07-28 09:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (193 votes), past polls