Rhino Mocks 3.0 Beta: Almost Ready
I just got a bing sound from the computer, telling me that an important message has arrived:
------ Test started: Assembly: Rhino.Mocks.Tests.dll ------
486 passed, 0 failed, 0 skipped, took 6.56 seconds.
Yup, that is correct. All, but all, of Rhino Mocks tests are currently passing. What is so suprising about Rhino Mocks passing all its tests? The surprising part is that now it is running on Dynamic Proxy 2, which means that there is support for mocking Generic Methods! This has long been Rhino Mock's weakest point, and it is now working!
Check out the syntax:
[Test]
public void CanCreateMockOfInterfaceWithGenericMethod()
{
MockRepository mocks = new MockRepository();
mocks.CreateMock<IFactory>();
}
[Test]
public void CanSetExpectationsOnInterfaceWithGenericMethod()
{
MockRepository mocks = new MockRepository();
IFactory factory = mocks.CreateMock<IFactory>();
Expect.Call(factory.Create<string>()).Return("working?");
mocks.ReplayAll();
string result = factory.Create<string>();
Assert.AreEqual("working?",result, "Should have worked, hm..." );
mocks.VerifyAll();
}
[Test]
[ExpectedException(typeof(ExpectationViolationException),@"IFactory.Create<System.Int32>(); Expected #1, Actual #1.
IFactory.Create<System.String>(); Expected #1, Actual #0." )]
public void WillGetErrorIfCallingMethodWithDifferentGenericArgument()
{
MockRepository mocks = new MockRepository();
IFactory factory = mocks.CreateMock<IFactory>();
Expect.Call(factory.Create<string>()).Return("working?");
mocks.ReplayAll();
factory.Create<int>();
}
[Test]
[ExpectedException(typeof(InvalidOperationException),"Type 'System.Int32' doesn't match the return type 'System.String' for method 'IFactory.Create<System.String>();'")]
public void WillGiveErrorIfThereIsTypeMismatchInGenericParameters()
{
MockRepository mocks = new MockRepository();
IFactory factory = mocks.CreateMock<IFactory>();
Expect.Call(factory.Create<string>()).Return(1);
}
[Test]
[ExpectedException(typeof(ExpectationViolationException), "IFactory.Create<System.String>(); Expected #1, Actual #0.")]
public void WillGiveErrorIfMissingCallToGenericMethod()
{
MockRepository mocks = new MockRepository();
IFactory factory = mocks.CreateMock<IFactory>();
Expect.Call(factory.Create<string>()).Return("working?");
mocks.ReplayAll();
mocks.VerifyAll();
}
What remains to do is to run some more tests (feel free to suggest some), implement some more accumolated bug fixes / feature requests that I have gathered, and release!
The last release was about three months ago, which is probably the longest time that Rhino Mocks had without a release. I am a bit afraid of release it, to tell the truth, every time that I do, I end up release another version shortly, with additional features/bug fixes. The problem is that the algorithm is recursive... :-)
Comments
Hear that? Do you hear it?
That's the sound of me drooling. Good work! Can't wait to use it! :)
Quick question, Ayende:
Normally are you using state-based unit testing or interactive-based testing?
Thanks!
A mixture of both, most often.
State based testing are easier to understand, interaction based tests are easier to work with for me.
DP2 also should be really faster than DP1. Did you notice any difference on tests execution speed?
About 50% faster or so, the whole suite of 500 tests takes less than 9 seconds to run
Rihno Mocks 3.0 on the horizon
Comment preview