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?
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.
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" );
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 .
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?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With