Given there is a "Sith Lord Lightsaber", which costs £5 When there is a "Sith Lord Lightsaber", which costs £10 Then there is an "Anakin Lightsaber", which costs £10
/** * Defines application features from the specific context. */ classFeatureContextimplementsContext, SnippetAcceptingContext { /** * Initializes context. * * Every scenario gets its own context instance. * You can also pass arbitrary arguments to the * context constructor through behat.yml. */ publicfunction__construct() { } }
在环境文件中, 我们可以定义如何解析基础步骤
1 2 3 4 5 6 7
/** * @Given there is a(n) :arg1, which costs £:arg2 */ publicfunctionthereIsAWhichCostsPs($arg1, $arg2) { thrownew PendingException(); }
或者通过正则的方式
1 2 3 4 5 6 7
/** * @Given /there is an? \"([^\"]+)\", which costs £([\d\.]+)/ */ publicfunctionthereIsAWhichCostsPs($arg1, $arg2) { thrownew PendingException(); }
编写特性文件
特性文件是一个由几个关键词组成的.feature文件
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
Feature: Some terse yet descriptive text of what is desired In order to realize a named business value As an explicit system actor I want to gain some beneficial outcome which furthers the goal
Additional text...
Scenario: Some determinable business situation Given some precondition And some other precondition When some action by the actor And some other action And yet another action Then some testable outcome is achieved And something else we can check happens too