2 回答

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

TA貢獻1811條經驗 獲得超6個贊
由于功能文件是您可以與業務利益相關者(或組織中的其他非 IT 人員)共享的內容,因此使用“現實世界”功能文件會更有意義。功能文件中的語言。 此外,當您在測試結束時將其傳遞給報告工具時,它會更具可讀性。
我會這樣處理。 switch 語句可以輕松地使用現實世界語言添加其他類型的日期:
[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
}
你的功能文件可能看起來像
Given the API returns items for 'yesterday'
when my function is run?
then I want that data in my database
- 2 回答
- 0 關注
- 194 瀏覽
添加回答
舉報