我正在嘗試運(yùn)行 behat,我制作了一個場景大綱,但跳過了一些帶有參數(shù)的行,并且一些變量被錯誤地使用了。這是寫在 .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貢獻(xiàn)1951條經(jīng)驗(yàn) 獲得超3個贊
使它們與眾不同的是 Gherkin 語法,在您的情況下:
@And a :password
相同@Given a :title
和相同@And an :email
因?yàn)?code>:password和其他只是一些標(biāo)簽,它們不是步驟的一部分。
Behat 認(rèn)為的一個步驟是:a <parameter>
添加其他不同的詞,例如:@Given a title :title
, @And a password :password
,@And an email :email
更好的是,我建議閱讀有關(guān) BDD 的最佳實(shí)踐。避免僅使用步驟來設(shè)置參數(shù),使用參數(shù)在數(shù)組中或以您需要的任何方式生成一組值。
- 1 回答
- 0 關(guān)注
- 127 瀏覽
添加回答
舉報(bào)
0/150
提交
取消