Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I make my Perl tests execute in a given order?

Tags:

testing

perl

When I use Test::Class and Test::More to do system testing, it seems that the test cases execute in parallel. My tests, however, have dependencies between them such that I would like to have tests executive in series. How can I do this?

like image 716
daisy Avatar asked Nov 26 '12 17:11

daisy


People also ask

What is prove in Perl?

Prove is a test running tool that ships with Perl. It has a ton of options, which can make it confusing for a beginner to use. If you have never used prove, or are not confident using it, do not despair! This article will get you up to speed with prove and it's most common options.

How do I write a test case in Perl?

Write Test Cases with Test::Simple #!/usr/bin/perl use strict; use warnings; use Test::Simple tests => 2; sub hello_world { return "Hello world!"; } sub get_number { return int(rand(1000)); } ok( hello_world( ) eq "Hello world!", "My Testcase 1" ); ok( get_number( ) > 0, "My Testcase 2" );


2 Answers

From the documentation of the module Test::Unit::TestCase in the NOTES section at the bottom:

If you need to specify the test order, you can do one of the following:

  • Set @TESTS

    our @TESTS = qw(my_test my_test_2);

    This is the simplest, and recommended way.

  • Override the list_tests() method

    to return an ordered list of methodnames

  • Provide a suite() method

    which returns a Test::Unit::TestSuite.

My personal 2 cents: Using Test::Class instead of Test::Unit::TestCase is probably a better alternative. The module documentation even has a good introduction, and a useful section on "Confused Junit Users" which you should be reading even if you keep using Test::Unit::TestCase .

like image 172
knb Avatar answered Sep 19 '22 21:09

knb


Test::Class executes its tests in alphabetic order. It's annoying, but you can name your test subroutines in a way that they will be executed in the proper order. Are you sure they are running in parallel? Are you possibly using prove on more than one file with a --jobs flag?

like image 36
gpojd Avatar answered Sep 21 '22 21:09

gpojd