【问题标题】:Behat with mink clean before each test每次测试前用貂皮清洁
【发布时间】:2014-06-17 21:55:09
【问题描述】:

我正在尝试找到一种在运行每个测试之前运行清理 (DB) 的方法。如果我将 behat 与貂一起使用,我该怎么办?我当前的 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
    }
}

【问题讨论】:

    标签: testing behat mink


    【解决方案1】:

    在您的上下文中使用钩子,阅读docs for Behat 3Behat 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
         }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-01-05
      • 1970-01-01
      • 2023-03-05
      相关资源
      最近更新 更多