It always amazes me when I find some little gem of functionality in a code library that I've used for some time. Today I was amazed to find out that RhinoMocks has a logging facility built into it, and I'm willing to bet this feature has been there for a long time and I just never noticed it.
Turning on RhinoMocks logging in your test fixture setup (or test) outputs all kinds of nifty informational messages about what RhinoMocks is doing. There appears to be 3 built in loggers in RhinoMocks:
Here's a simple test case using TraceWriterExpectationLogger (line 4):
1: [Test]
2: public void Should_login_user_with_valid_user_name_and_password()
3: {
4: RhinoMocks.Logger = new TraceWriterExpectationLogger();
5:
6: var userRepository = MockRepository.GenerateStub<IUserRepository>();
7: userRepository.Stub(x => x.GetUserByUserName("sneal")).Return(new User
8: {
9: UserName = "sneal",
10: Password = "password"
11: });
12:
13: var controller = new LoginController(userRepository);
14: controller.Login("sneal", "password");
15:
16: Assert.AreEqual("sneal", controller.UserContext.UserName);
17: }
You might have noticed I'm using the new AAA syntax in RhinoMocks 3.5. Very elegant. No setup method, no explicit replay or verify calls. I really like it.
Using the TraceWriterExpectationLogger looks like this from the ReSharper test runner, notice the trace messages from my mock:
So the next time you get stuck with an over complicated test session, try turning the logger on - I know I will.
Powered by: newtelligence dasBlog 2.1.8102.813
Disclaimer The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.
© Copyright 2012, Shawn Neal
E-mail