exception message (string comparison): nunit vs. DeepEqual
constructor-igor opened this issue · 3 comments
constructor-igor commented
NUnit:
Expected string length 3 but was 8. Strings differ at index 0.
Expected: "Joe"
But was: "Chandler"
-----------^
DeepEqual:
System.Exception : Comparison Failed: The following 1 differences were found.
Actual.Name != Expected.Name (Actual: "Chandler", Expected: "Joe")
jamesfoster commented
The nunit format is fine for a single comparison but DeepEqual
will return 1 line for each difference. This gets untidy when you have 3-4 lines per difference.
Do you want me to allow you to override the formatting of the message?
constructor-igor commented
I don't know good solution for message with several differences.
I use "deep equal" libraries for tests and good visual error message helps me to understand test's problem.
let's compare:
nunit:
Expected and actual are both <System.Collections.Generic.List`1[System.String]> with 4 elements
Values differ at index [1]
String lengths are both 20. Strings differ at index 12.
Expected: "String with 10 items"
But was: "String with 20 items"
-----------------------^
and deepequal:
System.Exception : Comparison Failed: The following 2 differences were found.
Actual[1] != Expected[1] (Actual: "data 20", Expected: "data 10")
Actual[2] != Expected[2] (Actual: "Sam2", Expected: "Sam1")
I guess, you agree, nunit message allows to understand first problem quickly.
constructor-igor commented
I created sample with "long" (>1000 symbols) strings:
nunit:
Expected string length 1538 but was 1539. Strings differ at index 501.
Expected: "...12211891925313013474130194418_first string_159148209974874..."
But was: "...12211891925313013474130194418_second string_15914820997487..."
--------------------------------------------^
deepequal:
Comparison Failed: The following 1 differences were found.
Actual != Expected (Actual: "00012305164844111411152110191622322913110728101733191151002962424923842214740823358912139233348542932275825565148366476156133372694550523638657677737721606882438929125791745673273128369044109675192961071850088651216811962397282116587491693147612824226977760126912913747911613318483926140153337854011315215815539551912463394314643175166231615614815218019221041741016499408813818212247167249118778176165613311212958145448161172881505712817786040102132116205115714803319015635112223416222413822615723914_second string_7111011194130233245657916238521065720266981181729108242292311251821581776312596542358419128352237862541451746279154233264201159185172274149264107180157187912118625188181217828822325228716625113712891562061893032852223162262742549211413923828820424562129514534121692332304663082203527730998348310341334451382592331422832972668218436834811229628815635317818431213693801863122280378155261693263532632352503572521386324215294151773801321236187136208157389254641609623413920350137662768162688459220131189118853381022701296032118642541632441220242725198111303333177644496263142134143204940543713315035039043135944119928429541318220265337382753634294061123585110627832215113011517157434953504291731041122632433723295127654421788916642363181511544131711277138136239353992981624142053821461904661871242175531334430460404274735142255015305449250129519137653414615362583011331832482465105495414406933321233972532423014381864254523791994002894764367115231573223217159194469181411405852778451031253942051255215626730943320542154655339658", Expected: "00012305164844111411152110191622322913110728101733191151002962424923842214740823358912139233348542932275825565148366476156133372694550523638657677737721606882438929125791745673273128369044109675192961071850088651216811962397282116587491693147612824226977760126912913747911613318483926140153337854011315215815539551912463394314643175166231615614815218019221041741016499408813818212247167249118778176165613311212958145448161172881505712817786040102132116205115714803319015635112223416222413822615723914_first string_7111011194130233245657916238521065720266981181729108242292311251821581776312596542358419128352237862541451746279154233264201159185172274149264107180157187912118625188181217828822325228716625113712891562061893032852223162262742549211413923828820424562129514534121692332304663082203527730998348310341334451382592331422832972668218436834811229628815635317818431213693801863122280378155261693263532632352503572521386324215294151773801321236187136208157389254641609623413920350137662768162688459220131189118853381022701296032118642541632441220242725198111303333177644496263142134143204940543713315035039043135944119928429541318220265337382753634294061123585110627832215113011517157434953504291731041122632433723295127654421788916642363181511544131711277138136239353992981624142053821461904661871242175531334430460404274735142255015305449250129519137653414615362583011331832482465105495414406933321233972532423014381864254523791994002894764367115231573223217159194469181411405852778451031253942051255215626730943320542154655339658")