2 回答

TA貢獻(xiàn)1829條經(jīng)驗(yàn) 獲得超7個(gè)贊
最簡(jiǎn)單的方法是編寫(xiě)一個(gè)特定于“立即”返回行項(xiàng)目的步驟:
Given the API returns items for right now
您可以從新版本調(diào)用該步驟的其他版本:
[Given(@"the API returns items for right now")]
public void GivenTheAPIReturnsItemsForRightNow()
{
GivenTheAPIReturnsItemsFor(DateTime.Now);
}
這避免了步驟之間的代碼重復(fù)。

TA貢獻(xiàn)1811條經(jīng)驗(yàn) 獲得超6個(gè)贊
由于功能文件是您可以與業(yè)務(wù)利益相關(guān)者(或組織中的其他非 IT 人員)共享的內(nèi)容,因此使用“現(xiàn)實(shí)世界”功能文件會(huì)更有意義。功能文件中的語(yǔ)言。 此外,當(dāng)您在測(cè)試結(jié)束時(shí)將其傳遞給報(bào)告工具時(shí),它會(huì)更具可讀性。
我會(huì)這樣處理。 switch 語(yǔ)句可以輕松地使用現(xiàn)實(shí)世界語(yǔ)言添加其他類(lèi)型的日期:
[Given("The API returns line items for '(.*)'")]
public void GivenTheAPIReturnsItemsForTime(string mydate)
{
? ? ?switch (mydate)
? ? ?{
? ? ? ? ? case:"the current date":
? ? ? ? ? ? ? HandleApiDateTime(DateTime.Now.ToString("dd-MM-yyyy"))
? ? ? ? ? ? ? // pass the current date to the Api handler
? ? ? ? ? ? ? break;
? ? ? ? ? case:"yesterday":
? ? ? ? ? ? ? HandleApiDateTime(DateTime.Now.AddDays(-1).ToString("dd-MM-yyyy"))
? ? ? ? ? ? ? // pass yesterdays date to the Api handler
? ? ? ? ? ? ? break;
? ? ? ? ? default:
? ? ? ? ? ? ? Console.Writeline("I didnt recognize this command");
? ? ? ? ? ? ? // or other error handling
? ? ? ? ? ? ? break;
? ? ?}
}
private void HandleApiDateTime(DateTime mydate)
{
? ? // do your api magic with a date object
}
你的功能文件可能看起來(lái)像
Given the API returns items for 'yesterday'
when my function is run?
then I want that data in my database
- 2 回答
- 0 關(guān)注
- 187 瀏覽
添加回答
舉報(bào)