Alex Rivera | Logout

Assert that arrays are equal in Visual Studio 2008 test framework

Asked 2009-05-22T12:14:22.300
93

Is there an easy way to check in a unit test that two arrays are equal (that is, have the same number of elements, and each element is the same?).

In Java, I would use assertArrayEquals (foo, bar);, but there seems to be no equivalent for C#. I tried Assert.AreEqual(new string[]{"a", "b"}, MyFunc("ab"));, but even though the function returns an array with "a", "b" the check still fails

This is using Visual Studio 2008 Team Suite, with the built-in unit test framework.

Edit
Report

1 Answer

4

In .NET 3.5, perhaps consider Assert.IsTrue(foo.SequenceEqual(bar)); - it won't tell you at what index it differs, though.

answered 2009-05-22T12:16:22.703

Your Answer