alfred-nutile-inc/behat-laravel

此包已被弃用且不再维护。没有建议替代包。

将Behat行为驱动开发测试添加到laravel 4

v1.5.1 2014-11-06 12:02 UTC

This package is not auto-updated.

Last update: 2018-05-08 20:44:26 UTC


README

ProjectStatus

Behat-Laravel 是一个使用行为驱动开发(BDD)方法测试应用程序的解决方案。

功能

当前

  • 创建用于接收验收测试的文件夹结构。
  • 运行验收测试。
  • Zizaco/TestCases-Laravel 集成,该工具提供了有用的测试应用程序的方法。

快速开始

所需设置

composer.json 文件的 require 键中添加以下内容:

"guilhermeguitte/behat-laravel": "dev-master"

运行 Composer 更新命令

$ composer update

在您的 config/app.php 中,将 'GuilhermeGuitte\BehatLaravel\BehatLaravelServiceProvider' 添加到 $providers 数组的末尾

'providers' => array(

    'Illuminate\Foundation\Providers\ArtisanServiceProvider',
    'Illuminate\Auth\AuthServiceProvider',
    ...
    'GuilhermeGuitte\BehatLaravel\BehatLaravelServiceProvider',

),

安装 selenium

http://docs.seleniumhq.org/download/

命令

现在使用以下 artisan 命令生成 Behat 的结构文件夹

$ php artisan behat:install

如果您不是使用 app/tests 文件夹的测试,可以传递测试路径。

$ php artisan behat:install --test_path==your/test/path

生成文档

只需运行以下命令即可创建 HTML 文档:

$ php artisan behat:html # will create a file at application's root

$ php artisan behat:html --out path/you/need/doc.html # will create a file specified path

结构

http://docs.behat.org/

添加上下文

当你在 tests\acceptance\contexts 文件夹中创建一个 context 时,此文件将被包含在 FeatureContext 中,防止指定用于测试的文件。

$ php artisan behat:feature --name=NameOfFeature

将会创建

    app\tests\acceptance\contexts\NameOfFeatureContext.php
    app\tests\acceptance\features\name_of_feature\name_of_feature.feature

运行测试

要运行所有测试,可以使用以下命令:

$ php artisan behat:run

要运行特定功能的测试,可以指定文件夹名称或 .feature 文件名

$ php artisan behat:run name_of_feature
$ php artisan behat:run name_of_feature/name_of_feature.feature
$ php artisan behat:run name_of_feature/separated_scenarios.feature

如果您有大型功能文件并且只想运行特定的场景,请使用

$ php artisan behat:run --name="name of feature"

Laravel behat 目前支持 behat 的以下命令行选项

 --format (-f)        How to format features. pretty is default.
                      Default formatters are:
                      - pretty: Prints the feature as is.
                      - progress: Prints one character per step.
                      - html: Generates a nice looking HTML report.
                      - junit: Generates a report similar to Ant+JUnit.
                      - failed: Prints list of failed scenarios.
                      - snippets: Prints only snippets for undefined steps.

 --no-snippets        Do not print out snippets
 --profile (-p)       Specify config profile to use.
 --name               Only execute the feature elements which match
                      part of the given name or regex.

许可证

Behat-Laravel 是在 MIT 许可证下分发的免费软件