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

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

有沒有辦法在多次調用函數(shù)時每次調用 AssertCalled

有沒有辦法在多次調用函數(shù)時每次調用 AssertCalled

Go
POPMUISE 2022-06-13 10:59:03
我正在嘗試使用stretchr/testify對如下代碼進行單元測試:func (c *MyClient) upsertData(data MyObject) {    upsertToDatabase(data)}func doSomething(c *MyClient) {    data1, data2 := getSomeData()    c.upsertToDatabase(data1)    c.upsertToDatabase(data2)}// Unit test.func TestDoSomething(t *testing.T) {    c := mock.MyClient{}    doSomething(c)    /* The following line checking for data1 upsert failed.     * require.True(t, c.AssertCalled(t, "upsertToDatabase", mock.MatchedBy(func(data MyObject) bool { return data == MyObject{expectedObject1 /* data2 */}})) */    require.True(t, c.AssertCalled(t, "upsertToDatabase", mock.MatchedBy(func(data MyObject) bool { return data == MyObject{expectedObject1 /* data2 */}}))}我想調用并AssertCalled驗證兩者確實是用預期的函數(shù)調用的。但是我只能在函數(shù)的最后一次調用中斷言,即使用. 有什么方法或我可以用它來斷言調用嗎?data1data2data2data1
查看完整描述

1 回答

?
慕無忌1623718

TA貢獻1744條經驗 獲得超4個贊

文檔中的示例:


/*

  Actual test functions

*/


// TestSomething is an example of how to use our test object to

// make assertions about some target code we are testing.

func TestSomething(t *testing.T) {


  // create an instance of our test object

  testObj := new(MyMockedObject)


  // setup expectations

  testObj.On("DoSomething", 123).Return(true, nil)


  // call the code we are testing

  targetFuncThatDoesSomethingWithObj(testObj)


  // assert that the expectations were met

  testObj.AssertExpectations(t)



}

看起來您可以調用.On任意次數(shù)來記錄任意數(shù)量的“以這種方式和這種方式調用”的期望。


我只是閱讀源代碼,真的。打賭它會比在 SO 上發(fā)帖更快。


查看完整回答
反對 回復 2022-06-13
  • 1 回答
  • 0 關注
  • 162 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號