Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can Test::Class tests be run in parallel? (or how to factor out superclass tests)

Tags:

testing

perl

In all the tutorials I've read for Test::Class, there seems to be one runner script that loads all of the classes. And I think from the perspective of Test::Harness this is just one giant test. I don't think it can parallelize the tests inside the runner.

My X problem is that I am trying to factor out superclass behaviors when testing subclasses. Each subclass should have its own subclass test (that can be parallelized), but also exercise behaviors inherited from the superclass. How does one that?

Edit: I found these two posts from 2007 that seem to imply that what I'm asking for is incompatible/not possible. Any update since then?

  • http://www.hexten.net/pipermail/tapx-dev/2007-October/001756.html (speculation for Test::Class to support parallelism
  • http://perlbuzz.com/2007/08/organizing-tests-with-testclass.html (implying that Test::Class and Test::Harness are ideologically exclusive)
like image 378
Mark Canlas Avatar asked Jun 15 '13 22:06

Mark Canlas


Video Answer


2 Answers

Test::Class doesn't support parallelisation on its own. Probably the easiest solution would be to have separate .t runners for each of your test classes (or for logical groups of test classes), and run using e.g. prove -j9.

If you really want to run all of the tests in parallel you could write a simple script to auto-generate a .t file for each test class. You'd lose the performance benefit of running multiple test classes within a single perl interpreter, but the parallelisation might compensate for the additional startup overhead. And I'd argue that no matter how much Test::Class tries to provide test isolation, it's impossible to guarantee that in Perl. Once you start taking advantage of modifying the symbol table for mocking purposes etc, your tests will start to interfere with each other unless you always get the cleanup right. Running each test in a separate perl interpreter is a better way to provide guaranteed isolation.

like image 166
simonp Avatar answered Nov 11 '22 13:11

simonp


To make Test::Class parallel, I had Used the following mechanism. Hope it could help you.

I had made use of the Parallel::ForkManager module to invoke the tests. But had

parameterized the TEST_METHOD environment variable, so that the required tests are run

in each thread parallely

This provides a isolation among other tests because, each test is invoked independently, and

the thread process is managed to wait until all the child process are completed

like image 42
Harshavardhan Konakanchi Avatar answered Nov 11 '22 15:11

Harshavardhan Konakanchi