Home > other >  Assert.AreEqual() giving unreliable results
Assert.AreEqual() giving unreliable results

Time:10-22

I have the following test:

Assert.AreEqual(descendants.Count(), 2);

It always passes when I run it alone but fails if I run it with all the other tests. Every time it fails is tells me that it is expecting an Expected value of 0 - even though my code clearly tells it to expect a value of 2:

Message: Assert.AreEqual failed. Expected:<0>. Actual:<2>.

What is happening here?

CodePudding user response:

Eric. There is a link about Assert.AreEqual Assert.AreEqual

The first parameter - descendants.Count() - expected

the second parameter - actual (2)

it should be in an opposite way, like

Assert.AreEqual(2,descendants.Count());

CodePudding user response:

Could this be a race condition? Race conditions in software or any system occur when the desired output requires that certain events occur in a specific order but that the events don’t always happen in that order. There is a ‘race’ between the events and if the wrong events win, the program fails. Usually happens in multi-thread applications.

  • Related