Assert.AreEqual在单元测试中失败 [英] Assert.AreEqual failing in unit test

查看:61
本文介绍了Assert.AreEqual在单元测试中失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下单元测试:

string MtrlCode = "0";
Assessment target = new Assessment(MtrlCode);

List<string> EdgeCaseSymbolCodes = new List<string>(); //More than 3
EdgeCaseSymbolCodes.Add("FLA");
EdgeCaseSymbolCodes.Add("HAR");
EdgeCaseSymbolCodes.Add("COR");
EdgeCaseSymbolCodes.Add("ENVON");
EdgeCaseSymbolCodes.Add("ENVR");
EdgeCaseSymbolCodes.Add("EXP");

target.HazardSymbols = EdgeCaseSymbolCodes;

List<string> EdgeCaseSymbolCodesExpected = new List<string>(); //Should be 3
EdgeCaseSymbolCodesExpected.Add("FLA");
EdgeCaseSymbolCodesExpected.Add("HAR");
EdgeCaseSymbolCodesExpected.Add("COR");

System.Windows.Forms.MessageBox.Show(EdgeCaseSymbolCodesExpected[0] + EdgeCaseSymbolCodesExpected[1] + EdgeCaseSymbolCodesExpected[2] + " = \n" + target.HazardSymbols[0] + target.HazardSymbols[1] + target.HazardSymbols[2]);

Assert.AreEqual<List<string>>(EdgeCaseSymbolCodesExpected, target.HazardSymbols, "COSHH_2008.Custom_Classes.Assessment.setHazardSymbols Edge Case did not return the expected value.");

正在测试边缘情况(在 List< string> 具有3个以上的元素),所需的输出仅是前3个的返回。

Which is testing an edge case (a time when the List<string> has more than 3 elements) with the desired output being the return of only the first 3.

当前测试失败了,我已经必须使用 MessageBox 来查看测试的内部(由于未命中断点!)。

Currently the test is failing and I've had to resort to using the MessageBox to see inside of the test (due to the breakpoints not being hit!).

从我所看到的元素是相同的,但是我意识到 List< string> 对象可能还有其他不同,但是我看不到

From what I can see the elements are the same, however I realise there might be something else different with the List<string> object, but I can't see this as the breakpoints are never been hit.

在Visual Studio 2005中找不到模块窗口。

I can't find the modules window in Visual Studio 2005.

下一步将是什么?

推荐答案

对列表的引用不同,请尝试

References to lists are different, try instead

Assert.AreEqual(EdgeCaseSymbolCodesExpected[0], target.HazardSymbols[0]);
Assert.AreEqual(EdgeCaseSymbolCodesExpected[1], target.HazardSymbols[1]);
Assert.AreEqual(EdgeCaseSymbolCodesExpected[2], target.HazardSymbols[2]);

这篇关于Assert.AreEqual在单元测试中失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆