Codeception失败测试需要很长时间才能运行

时间:2016-06-25 02:42:51

标签: unit-testing codeception

我刚刚为我的一些项目添加了Codeception,但其性能对于测试失败是不可接受的。传递测试在0.1秒或更短时间内执行,但是失败测试需要15分钟到1.5小时每个。当它们最终失败时,它们会向控制台倾倒数百千字节。有很多提到Selenium,我不明白,因为到目前为止我只使用单元测试,而不是验收测试或功能测试,所以我不明白它为什么需要Selenium。为什么这么慢?我可以配置一些东西,使失败的测试运行速度和通过测试一样快吗?这些是我正在使用的测试:

<?php

class englishTest extends \Codeception\Test\Unit {
  /**
   * @var \UnitTester
   */
  protected $tester;

  protected function _before() {
    include_once('country.model.php');
  }

  protected function _after() {
  }

  // tests
  public function testCreateCountryModel() {
    $country = new CountryModel;
    $this->assertEquals('Afghanistan', $country->get_all_countries()[0]);
  }

  public function testGetCountriesEndingWithEndOfWord() {
    $country = new CountryModel;
    $this->assertEquals(['Costa Rica', 'Dominica', 'Jamaica', 'South Africa'], $country->get_countries_ending_with('ca'));
  }

}

这是测试通过时的输出:

C:\server\Apache24\htdocs\localhost\public_html\english>codecept run
Codeception PHP Testing Framework v2.2.1
Powered by PHPUnit 4.8.26 by Sebastian Bergmann and contributors.

Acceptance Tests (0) ---------------------------------------
------------------------------------------------------------

Functional Tests (0) ---------------------------------------
------------------------------------------------------------

Unit Tests (2) ---------------------------------------------
+ englishTest: Create country model (0.1s)
+ englishTest: Get countries ending with end of word
------------------------------------------------------------


Time: 2.23 seconds, Memory: 11.00MB

OK (2 tests, 2 assertions)

修改

我创建了一个空白目录:

C:\server\Apache24\htdocs\localhost\public_html>md deception

我引导了Codeception:

C:\server\Apache24\htdocs\localhost\public_html>codecept bootstrap deception
 Initializing Codeception in C:\server\Apache24\htdocs\localhost\public_html\deception

File codeception.yml created       <- global configuration
tests/unit created                 <- unit tests
tests/unit.suite.yml written       <- unit tests suite configuration
tests/functional created           <- functional tests
tests/functional.suite.yml written <- functional tests suite configuration
tests/acceptance created           <- acceptance tests
tests/acceptance.suite.yml written <- acceptance tests suite configuration
 ---
tests/_bootstrap.php written <- global bootstrap file
Building initial Tester classes
Building Actor classes for suites: acceptance, functional, unit
 -> AcceptanceTesterActions.php generated successfully. 0 methods added
\AcceptanceTester includes modules: PhpBrowser, \Helper\Acceptance
AcceptanceTester.php created.
 -> FunctionalTesterActions.php generated successfully. 0 methods added
\FunctionalTester includes modules: \Helper\Functional
FunctionalTester.php created.
 -> UnitTesterActions.php generated successfully. 0 methods added
\UnitTester includes modules: Asserts, \Helper\Unit
UnitTester.php created.

Bootstrap is done. Check out C:\server\Apache24\htdocs\localhost\public_html\deception/tests directory

然后我改为目录并在其中运行以下命令:

C:\server\Apache24\htdocs\localhost\public_html\deception>codecept generate:test unit Deception
Test was created in C:\server\Apache24\htdocs\localhost\public_html\deception\tests\unit\DeceptionTest.php

然后我向DeceptionTest.php($this->assertTrue(false);)添加了一行:

<?php


class DeceptionTest extends \Codeception\Test\Unit
{
  /**
   * @var \UnitTester
   */
  protected $tester;

  protected function _before()
  {
  }

  protected function _after()
  {
  }

  // tests
  public function testMe()
  {
    $this->assertTrue(false);
  }
}

最后,我运行了以下内容:

C:\server\Apache24\htdocs\localhost\public_html\deception>codecept run
Codeception PHP Testing Framework v2.2.1
Powered by PHPUnit 4.8.26 by Sebastian Bergmann and contributors.

Acceptance Tests (0) ---------------------------------------
------------------------------------------------------------

Functional Tests (0) ---------------------------------------
------------------------------------------------------------

Unit Tests (1) ---------------------------------------------
x DeceptionTest: Me
------------------------------------------------------------


Time: 3.36 minutes, Memory: 103.25MB

There was 1 failure:

---------
1) DeceptionTest: Me
 Test  tests\unit\DeceptionTest.php:testMe
Failed asserting that false is true.
#1  C:\server\Apache24\htdocs\localhost\public_html\deception\tests\unit\DeceptionTest.php:22
#2  DeceptionTest->testMe
#3  C:\usr\bin\codecept.phar:7

FAILURES!
Tests: 1, Assertions: 1, Failures: 1.

如你所见, 3.36分钟 103.25MB 计算true !== false

1 个答案:

答案 0 :(得分:0)

我总是在PHP中使用Xdebug。在预感中,我禁用了它,然后突然,Codeception完成所有测试,只需几秒钟即可通过和失败。罪魁祸首是php.ini中的xdebug.collect_params = 3。将其设置为0,1或2可以解决问题。