为什么 Assert.IsInstanceOfType(0.GetType(), typeof(int)) 失败?
我对使用 Microsoft.VisualStudio.TestTools.UnitTesting 进行单元测试有点陌生;
0.GetType()
实际上是 System.RuntimeType
,那么我需要编写什么样的测试才能通过 Assert.IsInstanceOfType(0.GetType() ,typeof(int))
?
--- 接下来,这是我自己的用户错误... Assert.IsInstanceOfType(0, typeof(int))
I'm kind of new to unit testing, using Microsoft.VisualStudio.TestTools.UnitTesting
;
The 0.GetType()
is actually System.RuntimeType
, so what kind of test do I need to write to pass Assert.IsInstanceOfType(0.GetType(), typeof(int))
?
--- following up, this is my own user error... Assert.IsInstanceOfType(0, typeof(int))
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
将调用更改为以下
第一个参数是被测试的对象,而不是被测试对象的类型。 通过传递 0.GetType(),您所说的是“RunTimeType”是 System.int 的实例,这是错误的。 在幕后,这些电话只是决定
Change the call to the following
The first parameter is the object being tested, not the type of the object being tested. by passing 0.GetType(), you were saying is "RunTimeType" an instance of System.int which is false. Under the covers thes call just resolves to
看起来应该是
您的表达式当前正在评估 RunTimeType 是否是 RunTimeType 的实例,但事实并非如此。
Looks like it should be
Your expression is currently evaluating to see if RunTimeType is an instance of RunTimeType, which it isn't.