2017-04-20 31 views
0

我正在为我正在编写的项目编写API测试套件。运行单一测试时Codeception找不到类

我可以成功运行使用

codecept run api 

和套件中的所有测试都顺利通过,但每当我尝试运行使用

codecept run api Tests\Users\Get 

以下错误单个测试被抛出:

PHP Fatal error: Class 'Tests\ApiCest' not found in /Users/Username/Programming/PHP/Project/tests/api/Tests/Users/GetCest.php on line 12

这是我正在使用的文件夹结构:

Folder structure

ApiCest.php仅用于快速引导其他测试。下面是它的内容:

namespace Tests; 

/* 
* This class is extended by the API tests. 
*/ 
use ApiTester; 

class ApiCest 
{ 
    public function _before(ApiTester $I) 
    { 
     $I->prepareRequest(); 
    } 

    public function _after(ApiTester $I) 
    { 
     // All API responses must be in a JSON format. 
     $I->seeResponseIsJson(); 
    } 
} 

,这是它是如何在GetCest.php使用:

namespace Tests\Users; 

use ApiTester; 
use Codeception\Util\HttpCode; 
use Tests\ApiCest; 

/* 
* Tests for the GET /users API endpoint. 
*/ 
class GetCest extends ApiCest 
{ 
    // Tests methods are here but omitted 
} 

回答

2

这是因为Tests\Users\GetCest类扩展Tests\ApiCest类,但自动加载未建立了用于测试类。

此块添加到您的composer.json文件:

"autoload":{ 
    "psr-4":{ 
     "Tests\\": "tests/api/Tests" 
    } 
} 

如果你已经有autoload psr-4块,加上刚刚"Tests\\": "tests/api/Tests"行了。

+0

谢谢。我之前尝试过,但没有奏效。我想我没有做正确的:)哦,我也使用'autoload-dev'而不是'autoload'。 – siannone

相关问题