Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I test method call order with AAA syntax in Rhino-Mocks 3.6?

Is it possible to test for the following example if the Method1 called 1st, then Method2 called after and then Method3 by using the AAA syntax, in Rhino-mocks 3.6 ?

// Assert
var mock = MockRepository.GenerateMock<ISomeService>();

// Act
myObject.Service = mock;

// How should I change this part to ensure that Rhino Mocks check the call order as well?
mock.AssertWasCalled(m=>m.Method1());
mock.AssertWasCalled(m=>m.Method2());
mock.AssertWasCalled(m=>m.Method3());
like image 456
pencilCake Avatar asked Dec 28 '11 08:12

pencilCake


1 Answers

You can, but you really shouldn't. You should focus on testing the externall observable behaviors, rather than the implementation.

Method call order can change without affecting the contract with the client of the API. In that case, your test will fail, even when it shouldn't.

In short, testing implementation leads to brittle tests. Brittle tests lead to abandonment of the tests. You don't want to go there.

Hope this helps.

like image 149
Assaf Stone Avatar answered Sep 26 '22 17:09

Assaf Stone