【发布时间】:2017-12-17 17:15:45
【问题描述】:
下面是我的测试用例。两个字符串都是不同的对象,但我的测试用例通过了。
我预计他们会失败。因为它们是不同的对象。
string string1 = "Hello World";
string string4 = "Hello World";
Assert.AreSame(string1, string4);//Will return true
Assert.IsTrue(object.ReferenceEquals(string1,string4));
【问题讨论】:
-
正在使用的测试框架是什么?
-
MSTest 框架
-
重复/类似:stackoverflow.com/questions/9112610/… -tl;dr 编译时间常数
-
字符串由 CLR 保存在表中,如果要保存已经存在的字符串,它将只返回现有字符串的链接。
标签: c#