Wicket/MVC Architectural/Testing Question
I had to code something in Wicket (or take any MVC framework) that given 2 variables A and B provide the boolean result C which tells if something (a checkbox) is visible or not.
Now this is view logic, but let's say it is not as trivial as like: C = A && B; Maybe some automated testing is good to have.
Where would you put this logic? Is it okay to put it in the Model/Service layer and test it with JUnit ? In my understanding Model and Services are reserved for business logic.
Or do yo keep it in the View in which case you test it with something like Selenium ?
Or build some static method in some Utility package ?
I would build it as to get the thing done and build a test for it as simple as posible but not to mix it with the services开发者_开发技巧. So i would chose a static utility method.
I use also complex visibility logic in one of my wicket MVC project, and I put this logic into the service layer, and I test this code with JUnit. I also have wickettester test which tests the visibility of the checkbox also. I don't know what the best way is, but think this way is not bad. Hope it helps.
From a tech-agnostic p.o.v. I'd say this sounds like some logic that interacts with the view state. So this logic belongs with the presenter/controller.
Since the presenter/controller is a class - you should be able to test without bringing the view into the mix. I'm going by the MVP or MVVM idea.
It is view logic and as such it should be in the view layer.
Personally I would test this using Selenium. It depends how you are doing the visibility, using the wicket tester may be enough, but all view logic should be tested on real browsers using a tool like Selenium.
You should definitely not use a static utility method, for why see here
精彩评论