我正在尝试运行 behat,我制作了一个场景大纲,但跳过了一些带有参数的行,并且一些变量被错误地使用了。这是写在 .feature 上的小黄瓜场景大纲,其中包含已分配的功能:Scenario Outline: CreatePostUseCase service # tests/integration/BlogApp/Feature/BlogApp.feature:7 Given an <userid> # IntegrationTests\BlogApp\Context\BlogAppContext::aUserId() And an <email> // <- email row is skipped and no anEmail() function assigned And a <password> # IntegrationTests\BlogApp\Context\BlogAppContext::aTitle() // <- why is assigning aTitle() in password? When creating and saving a User object # IntegrationTests\BlogApp\Context\BlogAppContext::creatingAndSavingAUserObject() Given a <title> // <- why is not assigning aTitle() here? And a <body> // <- this one is also skipped When creating a Post object # IntegrationTests\BlogApp\Context\BlogAppContext::creatingAPostObject() Given a <publish> param # IntegrationTests\BlogApp\Context\BlogAppContext::aPublish() And persist the Post // <- this one is also skipped Then an event should be launched # IntegrationTests\BlogApp\Context\BlogAppContext::anEventShouldBeLaunched()这是上下文:/** * @Given an :userid */public function aUserId($userId){ $this->userId = $userId;}/** * @And an :email */public function anEmail($email){ $this->email = new Email($email);}/** * @And a :password */public function aPassword($password){ $this->password = new Password($password);}/** * @When creating and saving a User object */public function creatingAndSavingAUserObject(){ $this->user = new User($this->userId, $this->email, $this->password); $this->userRepository = new UserRepository(); $this->userRepository->save($this->user);}/** * @Given a :title */public function aTitle($title){ $this->title = $title;}/** * @And a :body */public function aBody($body){ $this->body = $body;}
1 回答
饮歌长啸
TA贡献1951条经验 获得超3个赞
使它们与众不同的是 Gherkin 语法,在您的情况下:
@And a :password相同@Given a :title和相同@And an :email因为:password和其他只是一些标签,它们不是步骤的一部分。
Behat 认为的一个步骤是:a <parameter>
添加其他不同的词,例如:@Given a title :title, @And a password :password,@And an email :email
更好的是,我建议阅读有关 BDD 的最佳实践。避免仅使用步骤来设置参数,使用参数在数组中或以您需要的任何方式生成一组值。
- 1 回答
- 0 关注
- 139 浏览
添加回答
举报
0/150
提交
取消
