国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Ruby > 正文

詳解Ruby on Rails中的Cucumber使用方法

2020-02-24 15:36:33
字體:
來源:轉載
供稿:網友

Cucumber使用Cucumber語法和文本描述語言來執行測試用例的工具,其中Cucumber描述軟件的行為,而不知道具體的實現,下文是武林技術頻道小編詳解Ruby on Rails中的Cucumber使用方法。
??? 用 @wip (工作進行中)標簽標記你未完成的場景。這些場景不納入考慮,且不標記為測試失敗。當完成一個未完成場景且功能測試通過時,為了把此場景加至測試套件里,應該移除 @wip 標簽。
??? 配置你的缺省配置文件,排除掉標記為 @javascript 的場景。它們使用瀏覽器來測試,推薦停用它們來增加一般場景的執行速度。

??? 替標記著 @javascript 的場景配置另一個配置文件。

??????? 配置文件可在 cucumber.yml 文件里配置。

    # 配置文件的定義:    profile_name: --tags @tag_name

??????? 帶指令運行一個配置文件:

    cucumber -p profile_name

??? 若使用 fabrication 來替換假數據 (fixtures),使用預定義的 fabrication steps。

??? 不要使用舊版的 web_steps.rb 步驟定義!最新版 Cucumber 已移除 web steps,使用它們導致冗贅的場景,而且它并沒有正確地反映出應用的領域。

??? 當檢查一元素的可視文字時,檢查元素的文字而不是檢查 id。這樣可以查出 i18n 的問題。

??? 給同種類對象創建不同的功能特色:

ruby;">  # 差  Feature: Articles  # ... 功能實作 ...  # 好  Feature: Article Editing  # ... 功能實作 ...  Feature: Article Publishing  # ... 功能實作 ...  Feature: Article Search  # ... 功能實作 ...

??? 每一個功能有三個主要成分:
??????? Title
??????? Narrative - 簡短說明這個特色關于什么。
??????? Acceptance criteria - 每個由獨立步驟組成的一套場景。

??? 最常見的格式稱為 Connextra 格式。

  In order to [benefit] ...  A [stakeholder]...  Wants to [feature] ...

這是最常見但不是要求的格式,敘述可以是依賴功能復雜度的任何文字。

??? 自由地使用場景概述使你的場景備作它用 (keep your scenarios DRY)。

?

  Scenario Outline: User cannot register with invalid e-mail   When I try to register with an email "<email>"   Then I should see the error message "<error>"  Examples:   |email     |error         |   |       |The e-mail is required|   |invalid email |is not a valid e-mail |

??? 場景的步驟放在 step_definitions 目錄下的 .rb 文件。步驟文件命名慣例為 [description]_steps.rb。步驟根據不同的標準放在不同的文件里。每一個功能可能有一個步驟文件 (home_page_steps.rb)
??? 。也可能給每個特定對象的功能,建一個步驟文件 (articles_steps.rb)。

??? 使用多行步驟參數來避免重復

??? 場景:?

User profile   Given I am logged in as a user "John Doe" with an e-mail "user@test.com"   When I go to my profile   Then I should see the following information:    |First name|John     |    |Last name |Doe     |    |E-mail  |user@test.com|  # 步驟:  Then /^I should see the following information:$/ do |table|   table.raw.each do |field, value|    find_field(field).value.should =~ /#{value}/   end  end

??? 使用復合步驟使場景備作它用 (Keep your scenarios DRY)

??? # ...
??? When I subscribe for news from the category "Technical News"
??? # ...

??? # 步驟:
??? When /^I subscribe for news from the category "([^"]*)"$/ do |category|
????? steps %Q{
??????? When I go to the news categories page
??????? And I select the category #{category}
??????? And I click the button "Subscribe for this category"
??????? And I confirm the subscription
????? }
??? end

??? 總是使用 Capybara 否定匹配來取代正面情況搭配 should_not,它們會在給定的超時時重試匹配,允許你測試 ajax 動作。 見 Capybara 的 讀我文件獲得更多說明。

  上述這則是詳解Ruby on Rails中的Cucumber使用方法,只要登陸武林技術頻道,無論你人在何地,都能夠輕松實現查詢,你不妨來試試吧。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表

圖片精選

主站蜘蛛池模板: 巴南区| 富民县| 阳西县| 卓尼县| 株洲市| 城口县| 沂水县| 惠来县| 通许县| 临安市| 宣威市| 明水县| 镇坪县| 桐城市| 左贡县| 铜山县| 信丰县| 驻马店市| 阿瓦提县| 桦南县| 铅山县| 孝昌县| 浦东新区| 阳泉市| 金秀| 大悟县| 阳高县| 南华县| 民乐县| 商水县| 环江| 广灵县| 永春县| 大同市| 扬州市| 太康县| 乡宁县| 闽侯县| 马边| 松阳县| 开封市|