我正在使用 NUnit 3.8.1,我正在尝试做一个非常简单的测试:
[TestCase(0)]
[TestCase(11)]
[TestCase(12)]
[TestCase(13)]
[TestCase(14)]
public void GivenUserCreatesPinWhenItIsInWrongPositionThenThrowArgumentException(uint position)
{
//Assert
Assert.Throws<ArgumentException>(() =>
{
new PositionPin(position);
});
}
我得到这个异常:
Message: System.ArgumentException : Object of type 'System.Int32' cannot be converted to type 'System.UInt32'
只要我将 uint 更改为 int 并将 int 转换为 uint,它就会在方法中生效。我真的不想这样做,有没有办法保留我的单位?
最佳答案
只需使用 u
直接告诉编译器,该数字是一个 System.UInt32
数字。
[TestCase(0u)]
[TestCase(11u)]
//...
或者:使用 int 作为参数并用 (uint) 进行转换
关于c# - 传递 UInt32 作为参数 TestCase NUnit,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46989397/