我正在对日期时间进行单元测试,但它失败了,因为测试名称:
有什么方法可以将字符串与日期时间进行比较,我是否必须更改字符串日期和字符串时间的属性?
public void GetDateTime()
{
FootballEvent football = new FootballEvent();
football.Time = "20:00:00";
football.Date = "28/05/2017";
var footballtime = football.GetDateTime();
var expected = "28/05/2017 20:00:00";
Assert.AreEqual(expected, footballtime);
}
最佳答案
正如有些人在评论中所说的那样,为什么不制作一个 DateTime
对象然后比较它们?
示例:
var footballtime = football.GetDateTime();
var expected = "28/05/2017 20:00:00";
DateTime expectedDate = DateTime.Parse(expected);
Assert.AreEqual(expectedDate, footballtime);
关于c#针对字符串单元测试日期时间,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/43262013/