tags:

views:

48

answers:

1

Hi I'm struggling to get mocks working, for a change, and was wondering where people generally put their mock classes. I seem to have three basic choices none of which seem to work.

I can put them in with the application assembly itself, in which case they ship with the application, which seems bad, but they are available for unit tests during the final builds and there are no circular references. This seems the simplest approach.

I can create a separate mock assembly, so they are available during the unit tests, can be consumed from the application and the test application but I end up with either having to move all of the actual types to this assembly or creating circular references.

I can put them in the test assembly, but then they are unable to be used from the application itself and therefore I cant use them as a process for building up chunks of the application.

I tend to try and use the mocks for helping develop the system as well as for the testing parts and therefore I find it hard to know where to put them. Additionally all of the final releases of code have to run through unit test processes therefore I need the mocks available during the build cycle.

Does anyone have any thoughts as to where mock classes should be placed?

thanks for any help T

+8  A: 

Your mocks should go in your unit tests projects. Your application should not be dependent on your mock objects. Generally your application will use interfaces and your mocks will implement those interfaces. Your application won't need to or should reference your test project.

adriaanp
So you would never use your mocks to speed up and work with your application? I started out having them in the unit test project but it seemed a huge waste if my application always had to talk all the way back to my back end while I had all of these perfectly functioning mocks there crying out to be used.
Tollo
"So you would never use your mocks to speed up and work with your application?" No; keep test code out of the application. Apart from the mocks, you've got unit testing code too: is that crying out to be used?
Tim Robinson
Sorry for the dupe between the two comments, but... The key difference between the unit testing code and the mocks is that my front end needs to used some form of the back end services and classes mostly before the other layers of developers have finished coding. I already have a lovely set of mocks for this in my test project it just seems a big shame not to be able to use them. Do you find all of the layers below you are already coded before you work on a front end?
Tollo
@Tollo mocking frameworks like RhinoMocks can help with the effort.
adriaanp
Tim/Adriannp thanks for the responses so far. Would RhinoMocks solve my issue of where to put the code? I have not looked at it but my understanding was it made the mocking process simpler rather than solved the issue of using mocks for both development and testing.
Tollo
I think you are confused about what a mocked object is. If you use an object in your application then that is not a mock object. Mock objects are there to simulate the behavior of REAL objects. http://en.wikipedia.org/wiki/Mock_object
adriaanp
sorry I just saw the click to show more comments hence the delay. I'm quite confused yes :( I have two simple requirements - first run unit tests against dummy data and second develop my front end against dummy data. I have classes (Which I call mocks) that contain excellent dummy data that behaves in a certain way. I guess that I should not join the two requirements together but keep them totally separate. I'm not going to do that as its a load of work but I can understand that is the answer to my question :) Thanks.
Tollo