the*_*ist 6 .net c# unit-testing mstest
我使用 MSTest.Framework/MSTest.TestAdapter 2.2.10。
Test_Method
我正在尝试使用属性传递测试数据DynamicData
。当struct和我 debugMyDateTime
时,的字段有错误的日期。但是,当我转到class时,我得到了正确的日期。可能是什么问题?我的装箱/拆箱有问题吗?Test_Method
_date
testData
MyDateTime
MyDateTime
[TestMethod]
[DynamicData(nameof(DataForTestMethod), DynamicDataSourceType.Property)]
public void Test_Method(MyDateTime testData)
{
}
public struct MyDateTime
{
private DateTime _date;
public MyDateTime(DateTime dt)
{
_date = dt;
}
}
public static IEnumerable<object[]> DataForTestMethod
{
get
{
var dt = new DateTime(2022,04,30,21,04,22);
var myDate = new MyDateTime(dt);
yield return new object[] { myDate };
}
}
Run Code Online (Sandbox Code Playgroud)
在使用 .net 反编译器一段时间后,似乎结构应该实现ISerializable
MSTest 框架的接口,以便通过 .net 正确返回数据DynamicDataAttribute
。的主体ISerializable.GetObjectData
甚至可以是空的(!)。我找不到负责加载的代码DynamicDataAttribute
来解释这一点,但如果我只添加接口,它似乎就可以工作ISerializable
。
归档时间: |
|
查看次数: |
457 次 |
最近记录: |