Tests with Behaviours
Writing unit tests with moles you specify the specific methods on the real system that you want to isolate. However and changes to your production code, e.g. changing from a call to SPList.Items1
to SPList.GetItemById(1), will result in your test not overriding the new method call and it trying to call into SharePoint for real. In orther words using isolation you unit tests tend to be brittle, which in turn adds to the cost of maintance.
The other problem is that you have to detour every method that is called, including the methods that is called by other moled methods, you test code becomes very tightly coupled with the code under test. You also find that the detour code can be quite verbose
and differcult to read.
To make writing detours easier you the Pex team have come up with the concept of behaviours. Behaviours are, in simple terms, a class that wraps up and abstracts away the details of writing moles behind a easy to use API. No longer do you need to isolate every
method call, now using behaviours you concentrate on defining the state that you require in order to perform the test.
For an example of using behaviours goto the following code link :-