Testing 每次试验前,用水貂清洗
我正在试图找到一种在运行每个测试之前运行清理(DB)的方法。如果我对水貂使用behat,我该怎么办?我当前的FeatureContext.php如下所示:Testing 每次试验前,用水貂清洗,testing,behat,mink,Testing,Behat,Mink,我正在试图找到一种在运行每个测试之前运行清理(DB)的方法。如果我对水貂使用behat,我该怎么办?我当前的FeatureContext.php如下所示: class FeatureContext extends MinkContext { /** * Initializes context. * Every scenario gets its own context object. * * @param array $parameters con
class FeatureContext extends MinkContext
{
/**
* Initializes context.
* Every scenario gets its own context object.
*
* @param array $parameters context parameters (set them up through behat.yml)
*/
public function __construct(array $parameters)
{
// Initialize your context here
}
}
在你的上下文中使用钩子,读或写。Behat 3中的示例:
// features/bootstrap/FeatureContext.php
use Behat\Behat\Context\Context;
use Behat\Testwork\Hook\Scope\BeforeSuiteScope;
use Behat\Behat\Hook\Scope\AfterScenarioScope;
class FeatureContext implements Context
{
/**
* @BeforeSuite
*/
public static function prepare(BeforeSuiteScope $scope)
{
// prepare system for test suite
// before it runs
}
/**
* @AfterScenario @database
*/
public function cleanDB(AfterScenarioScope $scope)
{
// clean database after scenarios,
// tagged with @database
}
}
在你的上下文中使用钩子,读或写。Behat 3中的示例:
// features/bootstrap/FeatureContext.php
use Behat\Behat\Context\Context;
use Behat\Testwork\Hook\Scope\BeforeSuiteScope;
use Behat\Behat\Hook\Scope\AfterScenarioScope;
class FeatureContext implements Context
{
/**
* @BeforeSuite
*/
public static function prepare(BeforeSuiteScope $scope)
{
// prepare system for test suite
// before it runs
}
/**
* @AfterScenario @database
*/
public function cleanDB(AfterScenarioScope $scope)
{
// clean database after scenarios,
// tagged with @database
}
}