0

My test code has the following assert:

testSubscriber.Called.Should().BeTrue("the handler was not called");

When it fails I get the following error message:

Expected True because the handler was not called, but found False.

English is not my native language, but this does not sound right, what should I write in the reason?

Calin
  • 6,661
  • 7
  • 49
  • 80

1 Answers1

2

The reason should be the reason why your assertion should pass. In your case, it appears you instead wrote the reason it would fail.

That parameter will be directly substituted into failure message. It will make sure not to repeat the word "because", so you can include that in the string which may make the code read more clearly.


Regarding the English for this particular case, the exact language I would use would depend on the situation.

If you are asserting that calling the handler sets Called to true, you might say case:

testSubscriber.Called.Should().BeTrue("because the handler was called");

which would result in the message

Expected True because the handler was called, but found False.


If you are confident that calling the handler will set Called to true, and you are instead trying to assert that the handler was called:

testSubscriber.Called.Should()
   .BeTrue("we expected the handler to have been called");

which would result in the message

Expected True because we expected the handler to have been called, but found False.

vossad01
  • 11,552
  • 8
  • 56
  • 109
  • Adam is correct. And as a side-note, why not use something like FakeItEasy so that you don't have to track calls to a class yourself. – Dennis Doomen May 31 '14 at 05:35
  • @DennisDoomen I am using moq for the mocking, but I tend to limit the use of mock to only my classes, in this particular case I was testing that a event was called on a third party event aggregator. – Calin Jun 02 '14 at 07:39