第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何編寫基于以前功能的 Cucumber 測試?

如何編寫基于以前功能的 Cucumber 測試?

婷婷同學(xué)_ 2023-10-12 14:50:13
我已經(jīng)開始使用 Cucumber 編寫 BDD 測試來匹配我的應(yīng)用程序的業(yè)務(wù)用例。它基于區(qū)塊鏈,因此測試中的每個用戶都在運行應(yīng)用程序的一個實例。這也意味著每次測試都相當(dāng)繁重,95%的測試時間都在準(zhǔn)備階段。當(dāng)我編寫測試時,我發(fā)現(xiàn)我開始重復(fù)自己,并且早期的功能似乎變得多余。一種業(yè)務(wù)流程是:用戶1保存一條新消息用戶2編輯消息User1 驗證編輯用戶1取消消息用戶2確認(rèn)取消這分為新建/編輯/取消功能。最初,我從“新建”和“編輯”功能文件開始,如下所示:新的Feature: a new message is added  Scenario: a user adds a new message    Given there is a user called User1    And there is a user called User2    When User1 creates a new message with id 1234    Then User2 should see the message with id 1234編輯Feature: Editing a message  Scenario: A User edits a message    Given there is a user called User1    And there is a user called User2    When User1 creates a new message with id 1234    And User2 adds the location US to the message    Then User1 should see the location US on the message但現(xiàn)在我進(jìn)入取消部分,我意識到為了正確測試取消,系統(tǒng)需要編輯消息,這意味著我需要完成新建和編輯功能以使消息進(jìn)入正確的狀態(tài)。這將使取消看起來像這樣,然后開始變得相當(dāng)冗長:取消Feature: Cancelling a message  Scenario: A User cancels a message    Given there is a user called User1    And there is a user called User2    When User1 creates a new message with id 1234    And User2 adds the location US to the message    And User1 cancels the message    Then User2 should see status Cancelled on the message我可以這樣寫取消:Feature: Cancelling a message  Scenario: A User cancels a message    Given there is a message with id 1234    And User1 cancels the message    Then User2 should see status Cancelled on the message作為一項功能,讀起來相當(dāng)不錯,但是,我現(xiàn)在必須為“有一條 id 1234 的消息”編寫一個步驟定義,該定義可以執(zhí)行“編輯”功能正在執(zhí)行的所有操作。正如在開始時提到的,這些測試中的設(shè)置占用了 95% 的測試時間,因此理想情況下,我希望將這些作為一系列步驟一起運行,而不是從每個功能的新鮮開始。例如進(jìn)行一次設(shè)置創(chuàng)建新消息編輯消息取消留言是否可以將場景或功能鏈接在一起并重用前一個場景或功能的系統(tǒng)狀態(tài)?還是每次都必須從頭開始啟動系統(tǒng)?調(diào)用構(gòu)成“編輯”功能的所有其他步驟/方法的步驟定義是否是“取消”的正確方法,還是應(yīng)該編寫大量 And 語句?
查看完整描述

2 回答

?
波斯汪

TA貢獻(xiàn)1811條經(jīng)驗 獲得超4個贊

我可以理解您對此的不滿,但后續(xù)功能無法相互構(gòu)建。每個場景都是原子的且可重復(fù)的。場景相互依賴的問題是,失敗的場景會導(dǎo)致后續(xù)場景中的級聯(lián)故障。應(yīng)用程序中的一個故障會觸發(fā)多個失敗的測試,導(dǎo)致您的團(tuán)隊開始認(rèn)為測試不可靠。

編寫一個模擬之前場景的步驟并沒有什么問題——這是正確的方法。定義這些步驟時,請盡可能保持它們的原子性,以便它們非??山M合。

老實說,6步場景就完全沒問題了。我建議的唯一更改是制作Given步驟的版本。取消When情況看起來對很多人來說都是如此。

Feature: Cancelling a message

  Scenario: A User cancels a message
    Given there is a user called User1
    And there is a user called User2
    And User1 created a new message with id 1234
    And User2 added the location US to the message
    When User1 cancels the message
    Then User2 should see status Cancelled


查看完整回答
反對 回復(fù) 2023-10-12
?
jeck貓

TA貢獻(xiàn)1909條經(jīng)驗 獲得超7個贊

原始:您可以從每個設(shè)置步驟中提取代碼并使它們起作用,將函數(shù)作為步驟的代碼調(diào)用(執(zhí)行與之前相同的任務(wù)),然后創(chuàng)建一個調(diào)用這些函數(shù)的新設(shè)置步驟,這意味著他們有一個共享的實現(xiàn)

替代方案:編寫一個帶標(biāo)記的 Before 掛鉤,它知道被測系統(tǒng)的狀態(tài),即使只是設(shè)置步驟是否已發(fā)生,并使用該信息針對這些情況重置系統(tǒng)。您甚至可以在此處執(zhí)行運行狀況檢查,以確保在系統(tǒng)需要時可以進(jìn)行完全重置。

或者甚至將此代碼放入步驟本身中,并讓他們知道如果運行狀況檢查已通過則跳過部分(很可能是 if 語句)


查看完整回答
反對 回復(fù) 2023-10-12
  • 2 回答
  • 0 關(guān)注
  • 141 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號