views:

58

answers:

2

Hey everyone,

I'm writing some unit tests for some controller methods in my project and am wondering whether to test against the controller class itself or an interface of that controller.

Should I be creating an interface for each controller and run my unit tests against that?

A: 

Do you have a need to treat your controllers as interfaces (quite unlikely I would of thought)? if so test against that. If not, then directly test against the controllers.

RichardOD
+6  A: 

You should test against the concrete conroller as that is where your site specifit code is occuring. You should inject service or data access code into the controller via their interfaces so that you can mock out the data access layer.

skyfoot
I also agree with this, you should test against the concrete class because that is what you should be testing. I would only use the controller's interface if that controller is a dependency of some other class that you want to test
adriaanp