Friday, 15 July 2011

unit testing - Rhino mocks - does this test look sensible? -


I have prepared the following tests using rhino socks. Is my test valid and more experienced people with jokes understand?

I am a little confused that I have to be emulating the Dynamicmock () or Strict Mac () methods to make a valid test.

This test is a test that the add method was applied to ICachingStrategy supplied with the supplied parameters.

  object o = new object (); Date time d = new date time (date time.N. year, date time.Now death, date time.Now day + 1, 0, 0, 0); Cashstoragestyle = CashStagestyle out of place; String F = "test"; // Organize stubStrategy = MockRepository.GenerateStub & lt; ICachingStrategy & gt; (); Var stubEncoder = MockRepository.GenerateStub & lt; ICacheItemEncoder & gt; (); StubStrategy.Stub (x = & gt; x.Add (O, D, S, F)). Return ("Test: Key"); StubEncoder.Stub (x = & gt; x.Encode (O, S)). Return (o); _mocks.ReplayAll (); // work ICache c = new cache (stubstraw, stub encoder); C. Add (O, D, S, F); // StubStrategy.AssertWasCalled (x = & gt; x.Add (O, D, S, F)) says;  

The question is: Is this successful? Do you expect this? If the answer is yes and yes, then the exam is good. You can test the test by complying to call it Add in its implementation. If the add () method is not called, the test should fail.

There are related documents that show the difference between stub and socks. The mandatory difference is that the stubbs "will not allow any examination to fail." They are just for testing code work, further recommend that wherever possible, the stubs above the mocks should be preferred.

Your test is valid for me because you are primarily interested in the fact that the add () method was called, and you have explicitly called that call Are pushing. You are not testing other methods of calls, so you are racking them instead of joking.


No comments:

Post a Comment