7

这是我的目录结构:

composer.json
composer.phar
vendor/
    bin/
        behat
tests/
    functional/
        behat.yml
        features/
            registration.feature
            bootstrap/
                FeatureContext.php

我做了:

cd tests/functional
../../vendor/bin/behat --init

这为我创造了基本结构。这是在 behat.yml 中:

default:
  paths:
    features: '%behat.paths.base%/features'
    bootstrap:  '%behat.paths.base%/features/bootstrap'

现在我尝试像这样运行 BDD 测试:

vendor/bin/behat -c tests/functional/behat.yml

我得到:

  [RuntimeException]                                                       
  Context class not found.                                                 
  Maybe you have provided 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] [--rerun="..."] [--append-snippets] [--append-to="..."] [features]

知道有什么问题吗?

我通过 Composer 安装了 Behat。这是我的composer.json:

{
    "name": "hello",
    "description": "Hello World",
    "minimum-stability": "dev",
    "require": {
        "php": ">=5.3",
        "zendframework/zendframework": "2.1.4",
        "doctrine/common": "dev-master#d7987c96675e153638729383577090feed9854f1"
    },
    "require-dev": {
        "phpunit/phpunit": "3.7.14",
        "behat/behat": "2.4.*@stable"
    }
}

我安装的是:

php composer.phar install --dev -o
4

2 回答 2

6

您在目录中时初始化了 Behat,tests/functional但您试图从根目录运行它。

修复路径:

default:
  paths:
    features: 'tests/functional/features'
    bootstrap:  'tests/functional/features/bootstrap'

tests/functional或者从目录运行 Behat 。

我建议保留原始文件布局(根目录中的功能)。 编辑:实际上,我尝试自己设置它,它与您提供的配置一起使用。一定有其他你在做的事情没有在问题中指定。

于 2013-04-10T14:58:04.340 回答
3

这是有效的。

cd tests/functional
../../vendor/bin/behat --init
cd ../../
vendor/bin/behat -c tests/functional/behat.yml

使用此配置文件:

default:
  paths:
    features: features
    bootstrap: features/bootstrap
于 2013-04-10T15:35:35.797 回答