你如何在 PHPUnit 中重复测试? [英] How do you repeat a test in PHPUnit?

查看:48
本文介绍了你如何在 PHPUnit 中重复测试?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道--repeat"选项,但我更愿意在测试和每个测试中定义重复.在我的单元测试中,有些测试我不想重复,有些测试我比其他测试更想重复.

I know about the "--repeat" option, but I'd rather define the repeating within the test and per test. In my unit tests there are tests I don't want to repeat, and there are tests I want to repeat more than others.

我在想:

protected function tearDown() {
  if (test has not been ran 3 times) {
      $this->runTest(); // Re-run the test
  }
}

这似乎不起作用,$this->run() 也不起作用.我看过 PHPUnit 源代码,但我不确定.我猜它正在检查测试状态,如果它已经运行,它会拒绝再次运行它.

This doesn't seem to work, nor does $this->run(). I've looked at the PHPUnit source code but I'm not sure. I'm guessing it's checking the test status and if it's been ran it denies running it again.

推荐答案

phpunit 在命令行运行器中有一个重复选项.对于重复 3 次的测试,其工作原理如下:

phpunit has a repeat option within the command line runner. This works as follows for a test which repeats 3 times:

phpunit --repeat 3 myTest.php

phpunit --repeat 3 myTest.php

这篇关于你如何在 PHPUnit 中重复测试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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