Run custom code after Codeception suite has finished

走远了吗. 提交于 2019-12-04 05:49:59

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
Luís Cruz

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