views:

52

answers:

2

Hi, could anyone give me a good example of using rhino mocks, nunit, and unity together. I am reading the help on each but there doesnt seem to be any good sample projects of how you would use them together and the way to set up projects /test projects using them. I.e. do you create new ioc containers in your test project which point to dummy classes. Then where does rhino come into it.

Thanks for any help.

+1  A: 

I use all 3 of these frameworks together. It looks like your problem is you are trying to learn too many things at once.

As for using an IoC container in tests, I've never had the need to do this for unit tests- I just use Rhino mocks to pass in stubs/mocks for dependent components as required.

For an integration test I could see the benefit of having an IOC container initialised in some code, for example if you were using the MVP pattern and wanted to completely replace a GUI with stubs.

I would first learn about Unit testing in more detail. I highly recommend the book The Art of Unit Testing. A good book that combines IOC, Unit testing and an isolation framework, I found was Pro ASP.NET MVC- there is now a 2nd edition, but as I've not read it, I can't really comment on it. The book doesn't use Unity, but if you learn how one framework works, it is easy to switch to using another. When I moved from Moq to Rhino, I found this wiki page particularly useful.

RichardOD
Thanks. I have seen those books got good reviews on amazon. I will give them a try.
peter pan
A: 

You don't need to use IoC in your unit tests. You should be testing the implementations of the interfaces and not the interfaces themselves.

Example: Person implements IPerson. You should have a PersonTests class that tests Person. You use Rhino Mocks to create a mock or stub of IPerson and test the functionality of the Person class.

(At least, that is the way I always do it).

You then have separate tests to test your IoC (if you need to).

Martin
Thanks for the prompt reply martin.
peter pan