// Art of unit testing (7.3.1 naming unit tests) // name of method being tested _ scenario being tested _ the expected behaviour // MethodUnderTest_Scenario_Behaviour [TestMethod] public void CreateParser_WellKnownDataset_PostsNodesToReciever() { MockRepository mocks = new MockRepository(); IParsedReceiver receiver = mocks.StrictMock<IParsedReceiver>(); using (mocks.Record()) { receiver.AcceptNode(null); LastCall.IgnoreArguments().Repeat.Times(14); } Parser parser = Manager.CreateParser(receiver, @"..\..\ParseData\OsmTestData.xml"); mocks.VerifyAll(); }
and using the 3.5 Arrange, Act, Assert approach:
// Art of unit testing (7.3.1 naming unit tests) // name of method being tested _ scenario being tested _ the expected behaviour // MethodUnderTest_Scenario_Behaviour [TestMethod] public void CreateParser_WellKnownDataset_PostsNodesToReciever_AsStub() { // arrange IParsedReceiver receiver = MockRepository.GenerateStub<IParsedReceiver>(); // act Parser parser = Manager.CreateParser(receiver, @"..\..\ParseData\OsmTestData.xml"); // assert receiver.AssertWasCalled(c => c.AcceptNode(null), options => options.Repeat.Times(14).IgnoreArguments()); }
which has the nice side effect of being less code as well!
No comments:
Post a Comment