Test::Class 测试可以并行运行吗?(或如何排除超类测试) [英] Can Test::Class tests be run in parallel? (or how to factor out superclass tests)

查看:60
本文介绍了Test::Class 测试可以并行运行吗?(或如何排除超类测试)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我为 Test::Class 阅读的所有教程中,似乎有一个运行器脚本可以加载所有类.我认为从 Test::Harness 的角度来看,这只是一个巨大的测试.我不认为它可以并行化运行器内部的测试.

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.

我的 X 问题是我试图在测试子类时排除超类的行为.每个子类都应该有自己的子类测试(可以并行化),但也要练习从超类继承的行为.那个怎么样?

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?

我发现 2007 年的这两篇帖子似乎暗示我所要求的不兼容/不可能.从那以后有更新吗?

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)

推荐答案

Test::Class 本身不支持并行化.可能最简单的解决方案是为每个测试类(或测试类的逻辑组)使用单独的 .t 运行器,并使用例如运行prove -j9.

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.

如果您真的想并行运行所有测试,您可以编写一个简单的脚本来为每个测试类自动生成一个 .t 文件.您将失去在单个 perl 解释器中运行多个测试类的性能优势,但并行化可能会补偿额外的启动开销.而且我认为无论 Test::Class 尝试提供多少测试隔离,都不可能在 Perl 中保证这一点.一旦您开始利用修改符号表进行模拟等目的,除非您总是正确地进行清理,否则您的测试将开始相互干扰.在单独的 perl 解释器中运行每个测试是提供有保证的隔离的更好方法.

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.

这篇关于Test::Class 测试可以并行运行吗?(或如何排除超类测试)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆