2012-03-07 121 views
72

我想用PHPUnit测试我的symfony2应用程序。我有一个项目,其中一切都按预期工作,但在另一个项目中,我有这种奇怪的行为,即PHPUnit在所有测试结束时随机停止执行测试套件,并在完成测试套件并编写代码后重新启动或重新启动测试覆盖。其他时候它正常运行。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可以重现这种行为?

+0

看起来它总是发生在同一个地方,65/83。你能找出它正在进行的测试吗?运行时尝试使用'--verbose'选项。 – 2012-03-08 19:27:41

+0

65/83意味着在第1行中,执行65个测试(每个点是一个测试)。在第二行中,您会看到执行的测试数量并不相同,因此我怀疑这是一项失败的测试。由于测试有时有效,有时会循环,我怀疑这是因为一次测试。但我会进一步调查! – Sgoettschkes 2012-03-09 08:36:16

+1

我的不好!我的脑子里有确实的知识。这里有个问题 - 你是否在一个孤立的PHP进程中运行每个测试?这可能会导致这种不寻常的活动。我们一直使用相同版本的PHPUnit,并且没有看到任何与您所看到的一样疯狂的东西! – 2012-03-09 08:59:22

回答

1

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

例如,如果您拥有100个连接的最大限制,并且某些测试将连接打开(“泄漏”),则会达到此限制。

这也可以解释为什么它有时会起作用,有时会达到极限,因为您的数据库可以同时处理其他任务,所以有时会达到天花板,其他时候没有其他任何运行时,您可以成功运行测试。

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