Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can we unit test View ('V') of MVC?

Duplicate: Unit Testing the Views?

Is there any way to unit test View? I am sure that we can test Model & Controller but don't know how to unit test View?

Is that worth testing View?

like image 957
Miral Avatar asked Jun 17 '09 08:06

Miral


2 Answers

You can enable compilation of MVC views. That helps a lot. Otherwise, I don't think it is worth it. After all, the there are only two things that you are interested in. Does view compile and do you get any exceptions (null, out of bounds exceptions, or similar)?

There are some folks who claim that you should not include any logic in view. Write helpers for anything. In that case, compilation is pretty much everything you'll want.

We decided to invest into WatiN testing. It tests views and it tests the whole app at the same time. Has some nice helpers, but requires constant maintainance.

like image 75
bh213 Avatar answered Oct 20 '22 00:10

bh213


Haven't views abandoned code behind now? So what are you going to test? If you are testing the controller, then you just need a succesful view result to show that the view works. Rather than going to the trouble of pre compiling views or whatever, this will start to drag any sizeable project down in terms of continuous integration, and build.

like image 29
Mark Dickinson Avatar answered Oct 20 '22 01:10

Mark Dickinson