Ngày nay trong các dự án Agile, cách tiếp cận theo BDD đang trở nên phổ biến hơn bao giờ hết thì việc làm thế nào để có thể viết được các file Testcase (*.feature) tốt, chuyên nghiệp giúp tất cả các thành viên (kể cả các thành viên ngoài đội dev) cũng hiểu được đang ngày càng trở nên cần thiết.
Với kinh nghiệm làm việc về Automation Test thời gian dài viết Gherkin, Anh Tester sẽ chia sẻ những kinh nghiệm của mình thông qua bài viết này.
Ví dụ: Thay vì viết theo kiểu diễn giải theo từng hành động như sau
Given I visit "/login"
When I enter "Bob" in the "user name" field
And I enter "tester" in the "password" field
And I press the "login" button
Then I should see the "welcome" page
Thì chỉ cần viết
When "Bob" logs in
[Bad]
Feature: Google searching
Scenario: Google search shows results
Given the user opens a web browser '<-- Present tense'
And the user navigates to "https://www.google.com/" '<-- Questionable hard coded test data (throughout)'
When the user enters "panda" into the search bar '<-- Imperative'
And the user presses the search button '<-- Imperative'
Then links related to "panda" are shown on the results page
When the user clicks on the "Images" link at the top of the results page '<-- Disrespectful of BDD syntax'
Then images related to "panda" are shown on the results page '<-- Disrespectful of BDD syntax'
[Good]
Feature: Google searching
Scenario: Searching on google returns accurate results
Given the google search page has been loaded '<-- Past tense'
When the user performs a search for "panda" '<-- Declarative, present-tense'
Then the returned results are accurate '<-- Declarative, present-tense, Respectful of the BDD syntax'
Các bạn có thể tham khảo bài BDD là gì để hiểu hơn về Gherkin nhé.
Trên đây là những gì mình rút ra được sau thời gian làm việc với Gherkin, các bạn có thể tham khảo nhé, cảm ơn rất nhiều !!!
Anh Tester
Đường dẫu khó chân vẫn cần bước đi
Đời dẫu khổ tâm vẫn cần nghĩ thấu