c# - Visual Studio Unit Testing Assert.AreEqual Fails with Identical Expected and Actual Values -


i total newb when comes unit testing, please pardon me if total ignorance. can't method pass unit test if provide exact same values expected , actual. when set breakpoints , step through, have confirmed both expected , actual variables string array containing 2 items, blah , blah. test still fails every time stating "assert.areequal failed. expected: system.string[] actual:system.string[]"

namespace testproject1  {  public class testing  {     public string[] pmdate(string lastpm)     {         if (string.isnullorempty(lastpm))             return new []{"blah", "blah"};         string[] results = lastpm.split(new[] {" "}, stringsplitoptions.none);          if (results.length < 2)             return new[] {"blah", "blah"};          return results;     }  } [testclass()] public class unittest1 {     [testmethod()]     public void pmdatetest()     {         testing test = new testing();         string[] expected = test.pmdate("01/01/1900");         string[] actual = test.pmdate("01/01/1900");         assert.areequal(expected, actual);     } } 

}

your test using object.equals, isn't overridden arrays. in other words, print false:

var x = new[] { 0 }; var y = new[] { 0 }; console.writeline(x.equals(y)); 

you should use collectionassert instead collections:

collectionassert.areequal(expected, actual); 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -