testfx icon indicating copy to clipboard operation
testfx copied to clipboard

Provide additional information for assert failures

Open codito opened this issue 6 years ago • 1 comments

Description

Default Assert methods should provide information in case of failures. They should at least answer the next question for a developer once a failure occurs. I've seen such behavior with CollectionAsserts, request to review other APIs as well.

Steps to reproduce

  1. Create a hello world test project
  2. Add two List<int> variables. var actual = { 1, 2, 3 } and expected = { 1, 3, 2 }
  3. Add an assert. CollectionAssert.AreEqual(expected, actual)
  4. Run tests

Expected behavior

A developer would immediately ask what were the elements if the collection doesn't match. Note the **additional** information below.

Failed   C.Tests.N.D
Error Message:
 CollectionAssert.AreEqual failed. (Element at index 1 do not match.)
 **Expected = { 2, 1, 3 }, Actual = { 1, 2, 3 }**
Stack Trace:
   at C.Tests.N.D()

Actual behavior

Failed   C.Tests.N.D
Error Message:
 CollectionAssert.AreEqual failed. (Element at index 1 do not match.)
Stack Trace:
   at C.Tests.N.D()

Environment

MSTest 1.2.0, VSTest 15.3.0, dotnet-sdk 2.0 (linux)

codito avatar Dec 17 '17 01:12 codito