当我在 C# 单元测试中编写以下代码时:
using Microsoft.VisualStudio.TestTools.UnitTesting;
CollectionAssert.AreEqual(new List<int> { 1, 2, 3 }, new List<int> { 1, 2 });
单元测试失败并显示以下详细信息:
Fehler bei "CollectionAssert.AreEqual". (Unterschiedliche Anzahl von Elementen.)
Error at "CollectionAssert.AreEqual". (Differing number of elements.)
现在我想知道为什么异常消息如此无用。写起来很容易:
Error at "CollectionAssert.AreEqual". (Expected 3 elements, got 2.)
当然,这一定是对CollectionAssert
那些不得不使用该类的开发人员或他们的同事造成了困扰。不提供详细信息的原因可能是什么,尤其是在单元测试期间?