8.3. Unit Testing

The first of these test categories is unit testing. Unit tests are targeted at the component level. They are tests that typically developers should write, maintain, and run to give them confidence that their components are working correctly before they check in their code changes to the source control system.

As already mentioned, if you are using a test-driven development approach, you will actually develop the unit tests before the code is written, so you will start with your unit tests failing and make the pass by implementing the code. In my view, mock objects provide a powerful tool when writing unit test cases. Mocks allow you to mock up dependencies and thereby enable you to test components in isolation from each other. Mock objects behave and look like the real objects; your component(s) can interact with them as though they were the real thing. You can set expectations on them to define how your component should interact with them. The expectations define which methods should be called, the parameters passed to them, and what the mock will return. At the end of the unit test case, you can ask the mocks to verify that the expectations were met. Failure to meet the expectations will cause a test case to fail. This often means a slightly different way of developing and can be a little alien at first, but it pays huge dividends. In my opinion, RhinoMocks is the best mock library for .NET 2.0 and can be downloaded from www.codeproject.com/useritems/Rhino_Mocks_22.asp ...

Get Professional BizTalk® Server 2006 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.