Run custom code after Codeception suite has finished

南楼画角 提交于 2019-12-21 13:06:28

问题


I am aware of the _bootstrap.php file that's used to set up the testing enviroment, etc., but I'm looking for a way to run some code after the entire test suite has finished.

Note that I'm not looking for a way to run code after a single class, i.e. something like _after, but after all classes.

Is there a way to achieve this?


回答1:


Actually managed to solve this myself, here's how, if anyone is interested.

I created a new helper class inside _support.

<?php

class DataHelper extends \Codeception\Module
{
    public function _beforeSuite()
    {
        // Set up before test suite
    }

    public function _afterSuite()
    {
        // Tear down after test suite
    }
}

You can then enable this as a module in any suite configuration (the .yml files), like this:

modules:
    enabled:
        - DataHelper



回答2:


@Sacha's solution is specially useful if you want to share the same methods accross all suites.

If you're looking for a way to define the methods for a specific suite (or if you want a different method per suite), you can define those methods directly in the suite Helper class.

For instance, if you want to define a _afterSuite method for the Acceptance Suite, just go to support/AcceptanceHelper.php and define those methods there. Eg:

<?php
namespace Codeception\Module;

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

class AcceptanceHelper extends \Codeception\Module
{
    public function _afterSuite() {
        die('everything done');
    }
}


来源:https://stackoverflow.com/questions/30242629/run-custom-code-after-codeception-suite-has-finished

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!