【发布时间】:2012-03-25 10:18:31
【问题描述】:
我正在尝试使用 PHPUnit 测试我的 symfony2 应用程序。我有一个项目,一切都按预期工作,但在我的另一个项目中,我有一个奇怪的行为,即 PHPUnit 在所有测试结束时随机停止执行测试套件并重新启动或在完成测试套件并编写代码后重新启动测试覆盖范围。其他时候正常运行。
这里有一些输出可以显示正在发生的事情(测试一遍又一遍地重新启动):
PHPUnit 3.6.10 by Sebastian Bergmann.
Configuration read from C:\workspace\cllctr\app\phpunit.xml
................................................................. 65 / 83 ( 78%)
...........PHPUnit 3.6.10 by Sebastian Bergmann.
Configuration read from C:\workspace\cllctr\app\phpunit.xml
................................................................. 65 / 83 ( 78%)
...PHPUnit 3.6.10 by Sebastian Bergmann.
Configuration read from C:\workspace\cllctr\app\phpunit.xml
................................................................. 65 / 83 ( 78%)
............PHPUnit 3.6.10 by Sebastian Bergmann.
Configuration read from C:\workspace\cllctr\app\phpunit.xml
................................................................. 65 / 83 ( 78%)
............PHPUnit 3.6.10 by Sebastian Bergmann.
Configuration read from C:\workspace\cllctr\app\phpunit.xml
................................................................. 65 / 83 ( 78%)
..................
Time: 01:03, Memory: 43.00Mb
OK (83 tests, 145 assertions)
Writing code coverage data to XML file, this may take a moment.
Generating code coverage report, this may take a moment.
这是一个测试套件在执行所有测试后重新启动的示例:
PHPUnit 3.6.10 by Sebastian Bergmann.
Configuration read from C:\workspace\cllctr\app\phpunit.xml
................................................................. 65 / 83 ( 78%)
..................
Time: 01:29, Memory: 53.25Mb
OK (83 tests, 145 assertions)
Writing code coverage data to XML file, this may take a moment.
Generating code coverage report, this may take a moment.
PHPUnit 3.6.10 by Sebastian Bergmann.
Configuration read from C:\workspace\cllctr\app\phpunit.xml
................................................................. 65 / 83 ( 78%)
............PHPUnit 3.6.10 by Sebastian Bergmann.
由于我的其他项目运行没有任何问题,我的代码中一定有问题。但我无法弄清楚是什么可能触发了这种行为!日志没有显示任何意外/奇怪的内容。
编辑
昨天,我注意到一些奇怪的事情:由于一些不相关的原因,我决定从 MongoDB 切换到 MySQL。转换完成后,所有测试都运行没有任何问题。我尝试了很多次,但我无法再复制它了。由于这只发生在我的功能测试中,我倾向于认为问题出在我的 WebTestCase 类,它运行一些命令来清除和重建数据库。也许也使用 MongoDB 的人可以重现这种行为?
【问题讨论】:
-
看起来它总是在同一个地方发生,65/83。你能找出它要进行的测试吗?运行时尝试使用
--verbose选项。 -
65/83 表示在第 1 行中执行了 65 个测试(每个点是一个测试)。在第二行中,您看到执行的测试数量不一样,所以我怀疑这是一个失败的测试。由于测试有时有效,有时循环,我怀疑这是因为一项测试。但我会进一步调查!
-
我的错!我确实在我的大脑某处拥有这些知识。这是一个问题 - 您是否在一个独立的 PHP 进程中运行每个测试?这可能导致了这种不寻常的活动。我们一直使用与您相同版本的 PHPUnit,从未见过像您所看到的那样疯狂的东西!
-
phpunit --debug会告诉你它正在运行哪个测试。 -
phpunit --testdox将显示测试名称 - 而不是点。
标签: unit-testing symfony phpunit