douyu9159 2018-11-01 13:58
浏览 56

Codeception Api套件助手不调用_beforeSuite(),_ afterSuite(),_ inititize()

I am refactoring an api test suite. I need to move a lot of code into Api helper class inside _beforeSuite($settings = []) & _afterSuite().

The problem is that these functions inside api helper class are not getting called for some reason when I start the suite.

My project structure

MyApiTests/
  ├── tests/
  │   ├── _data/
  │   │   ├── CommentsData.php
  │   │   ├── MyData.php
  │   │   └── TestData.php
  │   ├── _output/
  │   │   └── some failed reports
  │   ├── _support/
  │   │    ├── _generated
  │   │    │    └── ApiTesterActions.php 
  │   │    ├── Helper
  │   │    │    └── Api.php 
  │   │    └── ApiTester.php
  │   ├── api
  │   │    └── comments
  │   │        └── all my "comment" tests
  │   └── api.suite.yml
  ├── vendor (composer folder)
  ├── codeception.yml
  ├── composer.json
  └── composer.lock

/Helper/Api.php

namespace Helper;

require_once(__DIR__ . './../../_data/MyData.php');
require_once(__DIR__ . './../../_data/TestData.php');
require_once(__DIR__ . './../../_data/CommentsData.php');

// here you can define custom actions
// all public methods declared in helper class will be available in $I

class Api extends \Codeception\Module
{
    public function _beforeSuite($settings = [])
    {
        echo "TEST";

        parent::_beforeSuite($settings);

        $I = $this;
        $token = MyData::$tokenReadAndWrite;
        $json = CommentsData::$addCommentsProj;
        $keySingJson = CommentsData::$createKeySingular;
        $keyPluralJson = CommentsData::$createKeyPlural;

        $I->wantTo('Setup project and keys for comments');

        // create project for comments
        $projectId = $I->addProject($token,$json);

        // add singular key for adding comments
        $I->addKey($token, $projectId, $keySingJson);

        // add plural key for adding comments
        $I->addKey($token, $projectId, $keyPluralJson);

        echo "TEST";
    }

    public function _afterSuite()
    {
        parent::_afterSuite();
//        $I = $this;
//
//        $token = MyData::$tokenReadAndWrite;
//        $projectName = CommentsData::$projName;
//
//        $I->wantTo('deleting comments project');
//
//        // fetch the id of comments project
//        $projectId = $I->getProjectIdByName($token, $projectName);
//
//        $I->deleteProject($token, $projectId);
    }
}

api.suite.yml

actor: ApiTester
modules:
    enabled:
        - Api

codeception.yml

paths:
    tests: tests
    output: tests/_output
    data: tests/_data
    support: tests/_support
    envs: tests/_envs

actor_suffix: Tester

extensions:
    enabled:
        - Codeception\Extension\RunFailed


# suite config
suites:
    api:
        actor: ApiTester
        path: .
        modules:
            enabled:
                - REST:
                    url: http://someapp.local/api2/
                    depends: PhpBrowser
                - PhpBrowser:
                    curl:
                      CURLOPT_TIMEOUT: 300
                - Asserts
            config:
              REST:
                timeout: 90
              PhpBrowser:
                url: http://someapp.local/api2/
                curl:
                  CURLOPT_TIMEOUT: 300

I commented out all the code in _afterSuite() for debugging purpose. Tried different approaches with renaming the class, moving to other folder and rechecking my .yml files, and also tried changing _beforeSuite function to _initialize - no difference. I feel that I have missed something.

Update:

codecept build didn't helped

Response:

➜  MyApiTests codecept build

    ==== Redirecting to Composer-installed version in vendor/codeception ====
    Building Actor classes for suites: api
     -> ApiTesterActions.php generated successfully. 0 methods added
    \ApiTester includes modules: REST, PhpBrowser, Asserts
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 mmocr的训练错误,结果全为0
    • ¥15 python的qt5界面
    • ¥15 无线电能传输系统MATLAB仿真问题
    • ¥50 如何用脚本实现输入法的热键设置
    • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
    • ¥30 深度学习,前后端连接
    • ¥15 孟德尔随机化结果不一致
    • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
    • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
    • ¥15 谁有desed数据集呀