# Friday, June 27, 2008
« Requiring SSL at the Controller Level | Main | Unit Testing with a StreamReader »

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:

  • TraceWriterExpectationLogger
  • TraceWriterWithStackTraceExpectationWriter
  • TextWriterExpectationLogger

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:

image

So the next time you get stuck with an over complicated test session, try turning the logger on - I know I will.

Saturday, April 10, 2010 1:09:46 PM (GMT Standard Time, UTC+00:00)
If you are willing to buy real estate, you would have to get the home loans. Furthermore, my brother commonly takes a commercial loan, which occurs to be the most firm.
Thursday, April 29, 2010 4:12:48 PM (GMT Standard Time, UTC+00:00)
You should not be dazed just because your A grade! You just have to buy essay and be sure that you make proper steps in academic career construction.
Comments are closed.