21 March, 2015

UnitTesting – not all arrays are created equal

Attempting to compare 2 arrays today that indeed was supposed to be containing the exact same values using the Microsoft built-in Unit testing framework (Microsoft.VisualStudio.TestTools.UnitTesting), I was greatly surprised to learn that neither Assert.Equal nor Assert.AreSame does work for arrays?

It turns out that an entirely different Assert object is to be used for that purpose!
The CollectionAssert.AreEqual(expected, actual) is what you want to use for array comparison as seen below.

    //clone object
var newDisp = disp.CloneWithoutContentData();
Assert.IsNotNull(newDisp);
Assert.IsNotNull(newDisp.Content);

CollectionAssert.AreEqual(new byte[0], newDisp.Content.Data);
CollectionAssert.AreEqual(new byte[0], newDisp.AttachmentList[0].Content.Data);

Well – you learn every day (luckily!)


Technorati Tags: ,

No comments:

iPhone/XCode - not all cases are equal!

This bit me! Having made some changes to an iPhone application (Obj-C); everything worked fine in the simulator. But, when deploying the s...