C# – Assert that arrays are equal in Visual Studio 2008 test framework

cunit testingvisual-studio-2008

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.

Best Answer

It's CollectionAssert.AreEqual, see also the documentation for CollectionAssert.