What state should MockRepository be in when your imbetween tests?

17 views
Skip to first unread message

Sleazy

unread,
Jul 23, 2008, 9:05:20 AM7/23/08
to Rhino.Mocks
I know there are 3 states

- Record
- Replay
- Verify

but I'm having problems with my test picking up on expectations
outside of my

using (myMockRepository.Record())
{

}

blocks and I wanted to know what state should Rhino be in after a test
is complete. I assumed that Verify was correct and that finishing your
test with

using (myMockRepository.Playback)
{

}

would leave Rhino in the correct state for the next test. I have my
initialization of myMockRepository in my test fixture's [setup] method
and assumed that this would create a new one for each test preventing
the repository from recording expectations inbetween test but I don't
think that is working.


I have found that the best way to avoid setting premature expectations
and to only set your expectations is to do this

myMockRepository.BackToRecordAll() // resets all mock object so
nothing was accedientally recorded as an expectation
using (myMockRepository.Record)
{
// set expectations
}
// my assumption is that this using block leaves you in a non-record
state until you change it back to record or replay


Can someone please tell me what the best practices is for making sure
that you don't accidentally set expectations outside of your
using(myMockRepository.Record()) block. Eventhough my technique above
works it's syntactically awkward and it seems that .Record() would
implicitly reset the expectations but I guess not. Also, where should
the repository be created? Currently I do it in the test fixture's
[setup] method. Should I do some explicit destruction of the
repository in the test fixture [teardown] method?

jasonm...@gmail.com

unread,
Jul 23, 2008, 12:44:43 PM7/23/08
to Rhino.Mocks
within a given test the only thing outside of the record/playback
blocks is variables local to the test.
within the SetUp of each tests a declare a new repository.

private MockRepository = mockery;

[SetUp]
public void Setup
{
mockery = new MockRepository();
}

[Test]
public void TestOne()
{
using(mockery.Record())
{
}

using(mockery.Playback())
{
//place assertions here
}
}

[Test]
public void TestTwo()
{
using(mockery.Record())
{
}

using(mockery.Playback())
{
//place assertions here
Reply all
Reply to author
Forward
0 new messages