我使用Composer全新安装了Luracast / Restler,无法运行任何behat测试。我是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
我尝试使用绝对路径和相对路径指定paths.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项目,但我需要能够运行测试,所以我们将非常感谢帮助我解决这个问题。
答案 0 :(得分:1)
您是否使用behat --init
设置了Behat?
Behat需要功能和引导程序目录才能运行。您可以通过在命令行上输入behat --init
来创建它们。有关详细信息,请参阅Behat documentation:
在该目录中创建一个新目录并设置:
$ mkdir ls_project $ cd ls_project $ behat --init
behat --init
将创建一个features/
目录,其中包含一些基本内容,以便您开始使用。
Behat将为您的测试文件中的每一行运行一个测试方法。这些方法包含在上下文中。要编写Restler examples中使用的某种功能测试,您需要使用Restler附带的“RestContext
”。将vendor/luracast/restler/features/bootstrap
的内容复制到Behat引导程序目录中以便能够使用它们(您还需要FeatureContext.php
:这会实例化RestContext
)。
Restler的功能测试使用Guzzle,因此您还需要将其添加到composer.json
:
{
"require-dev": {
"guzzlehttp/guzzle": "~3.1.1"
}
}