【问题标题】:Restler tests with behatRestler 使用 behat 进行测试
【发布时间】:2014-01-03 05:23:54
【问题描述】:

我使用 Composer 重新安装了 Luracast/Restler,但无法运行任何行为测试。我是 Restler 和 behat 的新手,所以我可能会犯初学者的错误,但根据文档,我需要做的就是更改 behat.yml 中的根 URL,然后输入 bin/behat。

这是我在输入 vendor/bin/behat 时收到的错误消息。

  [RuntimeException]                                                         
  Context class not found.                                                   
  Maybe you have provided a wrong or no `bootstrap` path in your behat.yml:  
  http://docs.behat.org/guides/7.config.html#paths                           



behat [--init] [-f|--format="..."] [--out="..."] [--lang="..."] [--[no-]ansi] [--[no-]time] [--[no-]paths] [--[no-]snippets] [--[no-]snippets-paths] [--[no-]multiline] [--[no-]expand] [--story-syntax] [-d|--definitions="..."] [--name="..."] [--tags="..."] [--cache="..."] [--strict] [--dry-run] [--stop-on-failure] [--rerun="..."] [--append-snippets] [--append-to="..."] [features]


Content-type: text/html

这是我的 behat.yml 文件:

# behat.yml
default:
    context:
        parameters:
            base_url: http://<MY_DOMAIN>.com/restler3/sampleproject/public

我尝试使用绝对路径和相对路径指定 path.features 和 path.bootstrap 变量,但没有成功。

# behat.yml
default:
    paths:
        features: features
        bootstrap:  features/bootstrap
    context:
        parameters:
            base_url: http://<MY_DOMAIN>.com/restler3/sampleproject/public

我真的很想将 Restler 用于我正在启动的 API 项目,但我需要能够运行测试,所以如果能帮助我解决这个问题,我将不胜感激。

【问题讨论】:

    标签: behat restler


    【解决方案1】:

    您是否使用 behat --init 设置了 Behat?

    Behat 需要功能和引导目录才能运行。您可以通过在命令行输入behat --init 来创建这些。有关更多信息,请参阅Behat documentation

    创建一个新目录并在该目录中设置行为:

    $ mkdir ls_project
    $ cd ls_project
    $ behat --init
    

    behat --init 将创建一个 features/ 目录,其中包含一些让您入门的基本内容。

    Behat 将为您的测试文件中的每一行运行一个测试方法。这些方法包含在 contexts 中。要编写Restler examples 中使用的那种功能测试,您需要使用 Restler 附带的“RestContext”。将 vendor/luracast/restler/features/bootstrap 的内容复制到您的 Behat 引导目录中,以便能够使用这些内容(您还需要 FeatureContext.php:这会实例化 RestContext)。

    Restler 的功能测试使用 Guzzle,因此您还需要将其添加到您的 composer.json

    {
       "require-dev": {
          "guzzlehttp/guzzle": "~3.1.1"
       }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-10-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多