2015-10-22 102 views
3

我有这个问题,我很难解决。我使用的是Codeception 1.8.7,因为我们需要使用PHP 5.3。Codeception测试运行两次

正如您在下面的代码中看到的,它是一个非常简单的测试来解释问题。 我声明一个计数器并显示它。当运行“tryToTest”方法时,我递增计数器; 然后我显示计数器;一次使用echo()和一次使用amGoingTo()方法。

<?php 
use \ApiGuy; 

class debugCest 
{ 

    public $testCounter = 0; 

    public function _before() 
    { 
     echo "Before 1"; 
    } 

    // tests 
    public function tryToTest(ApiGuy $I) { 
     $this->testCounter++; 
     echo "\n COUNTER A: " . $this->testCounter; 
     $I->amGoingTo('show COUNTER B: '. $this->testCounter); 


    } 

} 

现在,当我们运行测试。我们期望tryToTest()方法只能运行一次,对吧?

所以,当我们运行

php codecept run api debugCest.php 

这应该是我们期望的输出:

Codeception PHP Testing Framework v1.8.7 
Powered by PHPUnit 3.7.37 by Sebastian Bergmann. 

COUNTER A: 1 
Api Tests (1) ----------------------------------------- 
Trying to try to test (debugCest.tryToTest) 
Scenario: 
* I am going to show COUNTER B: 1 
PASSED 

------------------------------------------------------- 

Time: 844 ms, Memory: 7.75Mb 

OK (1 test, 0 assertions) 

但出于某种原因,这是我的输出,似乎方法“TryToTest”运行两次? ?

Codeception PHP Testing Framework v1.8.7 
Powered by PHPUnit 3.7.37 by Sebastian Bergmann. 

COUNTER A: 1 
Api Tests (1) ----------------------------------------- 
Trying to try to test (debugCest.tryToTest) 
Scenario: 
* I am going to show COUNTER B: 2 
PASSED 

------------------------------------------------------- 

Time: 844 ms, Memory: 7.75Mb 

OK (1 test, 0 assertions) 

我是我做错了什么?为什么它运行两次

编辑:似乎这个问题已修复与较新的版本2.1。 相关问题:https://github.com/Codeception/Codeception/issues/582

回答