CodingGorilla
unread,Mar 20, 2012, 9:30:42 AM3/20/12Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Rhino.Mocks
I have a unit test in which I am generating some mocks
using .GenerateMock<>(). If I run the unit test alone (ie. not other
tests before or after) then the test passes. But when I run then
entire suite, the test fails. Let me start with a bit of the test
code:
ICountryDataCache countryDataCache =
MockRepository.GenerateMock<ICountryDataCache>();
countryDataCache.Expect(x =>
x.GetCountryIdFromName("Canada")).Repeat.Any().Return(canadaId);
countryDataCache.Expect(x =>
x.GetCountryIdFromName(Constants.WellKnownLabels.UnitedStates)).Return(usId);
childContainer.RegisterInstance(countryDataCache);
I enable logging with RhinoMocks.Logger, and when I run the test
alone, I get this output.
Recorded expectation:
ICountryDataCache.GetCountryIdFromName("Canada");
Recorded expectation:
ICountryDataCache.GetCountryIdFromName("United States");
...
Replayed expectation:
ICountryDataCache.GetCountryIdFromName("Canada");
...
Replayed expectation:
ICountryDataCache.GetCountryIdFromName("United States");
That's what I would expect. However, when I run the entire suite, the
output is different:
Recorded expectation:
ICountryDataCache.GetCountryIdFromName("Canada");
Recorded expectation:
ICountryDataCache.GetCountryIdFromName("United States");
...
Stub Mock: Unexpected method call ignored:
ICountryDataCache.GetCountryIdFromName("Canada");
...
Stub Mock: Unexpected method call ignored:
ICountryDataCache.GetCountryIdFromName("United States");
So this is what I don't understand; it's the same code, but the
logging shows it as a "Stub Mock", and then tells me that it was an
unexpected method call. Can anyone explain this?