use*_*707 0 testing behat mink
我试图找到一种在运行每个测试之前运行清理 (DB) 的方法。如果我将 behat 与 mink 一起使用,我该怎么办?我当前的 FeatureContext.php 看起来像这样:
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
}
}
Run Code Online (Sandbox Code Playgroud)
在您的上下文中使用钩子,阅读Behat 3或Behat 2 的文档。来自 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
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2600 次 |
| 最近记录: |