N-tier architecture and unit tests (using Java)
Posted
by
Alexandre FILLATRE
on Stack Overflow
See other posts from Stack Overflow
or by Alexandre FILLATRE
Published on 2011-01-12T17:05:30Z
Indexed on
2011/01/13
1:53 UTC
Read the original article
Hit count: 325
Hi there,
I'd like to have your expert explanations about an architectural question. Imagine a Spring MVC webapp, with validation API (JSR 303). So for a request, I have a controller that handles the request, then passes it to the service layer, which passes to the DAO one.
Here's my question. At which layer should the validation occur, and how ?
My though is that the controller has to handle basic validation (are mandatory fields empty ? Is the field length ok ? etc.). Then the service layer can do some tricker stuff, that involve other objets. The DAO does no validation at all. BUT, if I want to implement some unit testing (i.e. test layers below service, not the controllers), I'll end up with unexpected behavior because some validations should have been done in the Controller layer. As we don't use it for unit testing, there is a problem.
What is the best way to deal with this ? I know there is no universal answer, but your personal experience is very welcomed.
Thanks a lot. Regards.
© Stack Overflow or respective owner