The SitePoint Forums have moved.

You can now find them here.
This forum is now closed to new posts, but you can browse existing content.
You can find out more information about the move and how to open a new account (if necessary) here.
If you get stuck you can get support by emailing forums@sitepoint.com

If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

unit testing and MVC

When using unit testing to develop something in an MVC style architecture, what components do you actually test?

Say if you've got an ArticlesModel, ArticlesController and ArticlesView, do you write seperate tests for these (TestOfArticlesModel, TestOfArticlesController and TestOfArticlesView) or one all-encompassing test TestOfArticles?

Right now I'm testing them all individually and I seem to be repeating myself a lot, which smacks of inefficiency...

Testing often depends on your Use Cases. If your site is heavily UI oriented, I would suggest using something Selenium. If there are a lot of entry points into your controllers, you can write tests that hit the controllers directly outside of an actual web request (possibly use Mock Objects to simulate a web request).

BUT!!! (That's three exclamation points, my friend.)

Always write tests for your back-end. You must test your domain model and its behavior, especially if there is complex business logic within your domain classes. Unit tests are the standard for this, and most languages have a Unit test framework out there. You can also use Unit tests for the front-end stuff, like Selenium and to test your controllers. A clean way is to integrate all your tests into one large test suite and run that regularly (even after a trivial refactor, you need to run the tests).

Make sure all model classes are thoroughly unit tested. I found that unit testing controllers is too much hassle for my application, so I (integration) test them together with their associated classed (no mocks). Testing views should be possible with web test frameworks, but you might run into problems if your application uses fancy javascript - at least I did a few years ago. This might have changed.

integration testing is something that is more easily done from the client-side of your application

does that mean a web test case suffices as an integration test?

but if a particular controller method issues a redirect, how can this be caught with a unit test versus a web test? is that the expectContinuation method Marcus posted previously? (which I still have no idea what that is .. lol)