1 回答

TA貢獻(xiàn)1875條經(jīng)驗(yàn) 獲得超5個(gè)贊
StateHandlers不直接更改響應(yīng)(這可能會(huì)影響測(cè)試的有效性),它們的存在是為了修改當(dāng)前測(cè)試的提供者的內(nèi)部狀態(tài)。使用狀態(tài)名稱(以及可選的參數(shù))來確定應(yīng)該配置什么狀態(tài)。
當(dāng)測(cè)試執(zhí)行時(shí),提供者應(yīng)該在適當(dāng)?shù)臓顟B(tài)下執(zhí)行其通常的代碼,并做出相應(yīng)的響應(yīng)。
StateHandlers: StateHandlers{
"A product with id 1 exists": func(setup bool, s ProviderStateV3) (ProviderStateV3Response, error) {
// modify internal state of the provider, so that product with ID 1 exists in the database
return response, nil
},
"A product with id 2 doesn't exists": func(setup bool, s ProviderStateV3) (ProviderStateV3Response, error) {
// modify internal state of the provider, so that product with ID 2 does not exist in the database
},
},
存儲(chǔ)庫中有示例,例如https://github.com/pact-foundation/pact-go/blob/master/examples/mux/provider/user_service_test.go#L94-L120。
狀態(tài)是抽象的——它并不暗示狀態(tài)是如何配置的。它可以通過更新數(shù)據(jù)庫或配置存根等多種方式實(shí)現(xiàn)狀態(tài)轉(zhuǎn)換。
- 1 回答
- 0 關(guān)注
- 114 瀏覽
添加回答
舉報(bào)