phpunit随机重新启动测试



我正在尝试使用PHPUnit测试我的symfony2应用程序。我有一个项目的一切都如预期,但在我的另一个项目中,我有一种奇怪的行为,即PHPUnit要么在所有测试结束时随机停止执行测试套件,要么在完成测试套件并编写代码覆盖率后重新启动或重新启动测试。其他时候它运行正常。

以下是一些输出,以显示正在发生的事情(测试正在反复重新启动):

PHPUnit 3.6.10 by Sebastian Bergmann.
Configuration read from C:workspacecllctrappphpunit.xml
................................................................. 65 / 83 ( 78%)
...........PHPUnit 3.6.10 by Sebastian Bergmann.
Configuration read from C:workspacecllctrappphpunit.xml
................................................................. 65 / 83 ( 78%)
...PHPUnit 3.6.10 by Sebastian Bergmann.
Configuration read from C:workspacecllctrappphpunit.xml
................................................................. 65 / 83 ( 78%)
............PHPUnit 3.6.10 by Sebastian Bergmann.
Configuration read from C:workspacecllctrappphpunit.xml
................................................................. 65 / 83 ( 78%)
............PHPUnit 3.6.10 by Sebastian Bergmann.
Configuration read from C:workspacecllctrappphpunit.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:workspacecllctrappphpunit.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:workspacecllctrappphpunit.xml
................................................................. 65 / 83 ( 78%)
............PHPUnit 3.6.10 by Sebastian Bergmann.

由于我的另一个项目运行时没有任何问题,所以我的代码中一定存在一些问题。但我不知道是什么可能引发这种行为!日志没有显示任何意外/奇怪的东西。

编辑

昨天,我注意到了一件奇怪的事情:由于一些无关的原因,我决定从MongoDB切换到MySQL。转换完成后,所有测试都可以顺利运行。我试了很多次,但我再也无法复制了。由于这只发生在我的功能测试中,我倾向于认为问题出在我的WebTestCase类上,它运行一些命令来清除和重建数据库。也许同样使用MongoDB的人可以重现这种行为?

我建议检查数据库服务器连接限制和池。

例如,如果您的最大连接数为100,而某些测试使连接处于打开状态("泄漏"),那么您就达到了限制。

这也解释了为什么有时它能工作,有时它达到极限,因为你的数据库可以同时处理其他任务,所以有时你达到了极限,有时当没有其他任务运行时,你可以成功地运行测试。

检查持久网络连接和其他外部资源。

最新更新