Ayende @ Rahien

My name is Oren Eini
Founder of Hibernating Rhinos LTD and RavenDB.
You can reach me by phone or email:


+972 52-548-6969

, @ Q c

Posts: 6,128 | Comments: 45,550

filter by tags archive

Presentation Logic & Semi Integration Tests

time to read 2 min | 397 words

Scott has an interesting view about my post regarding testing presentation logic:

However, his answer to this issue involves basically executing a dynamic page (in MonoRail) and testing the HTML output.  He admits that this is a "semi-integration test".  I would agree with that, except for the "semi" part.  If I really wanted to execute a page at the unit testing stage, I could use a tool like NUnitAsp, which operates at the same level of abstraction as ASP.NET server controls and thus insulates the test code somewhat from the actual rendered HTML markup.

I call it semi integration test because the only part of the code that I exercise is the view code, and it is integration because I have to verify the textual result, rather than the objects themselves.

Scott's suggestion about using something like NUnitAsp is a true integration test, because it execute the entire pipeline, including the controller, data access, etc. That is not the purpose of the test, I just want to validate presentation code, not the whole thing. NUnitAsp is also not applicable because it uses WebForms, which is not something that I willingly use.

Another very good point Scott is making:

Finally, forget testability for a minute and consider something I was taking for granted.  Continuing with the banded report example, what happens when the subtotals are needed in a different view?  Or in the output of a web service?  If that calculation is buried inside a specific view, look at the bright side:  At least you'll have plenty of opportunity to practice your refactoring.

If I need it in more than a single place, then it would be the time to consider refactoring. If I needed it in another view, I would probably refactor to a subview, which is a ridiculously easy to do. I doubt that I would need to do it in a web services, since that is calculable information, and would usually cause more harm than good.

At any rate, I feel that pushing this to the domain level is not something that I would really want to do, it is purely presentation logic, meant for the user, without any correlation to the domain. If I had to use it in several places, I would a presentation layer class that would take care of it, but that is still presentation logic.


Scott McMaster

I agree with you about the granularity of testing provided by NUnitAsp, and in fact, I had the word "unit" in quotes in my original draft of that post. I just wanted to point out that those who use WebForms can easily perform, well, whatever kind of testing it is that we're talking about if they want to.

Whether it's "purely presentation logic" or not is probably in the eye of the beholder, or eye of the use case. It's far from necessarily the case that "calculated logic" == "presentation logic".



Comment preview

Comments have been closed on this topic.


  1. The worker pattern - about one day from now

There are posts all the way to May 30, 2016


  1. The design of RavenDB 4.0 (14):
    26 May 2016 - The client side
  2. RavenDB 3.5 whirl wind tour (14):
    25 May 2016 - Got anything to declare, ya smuggler?
  3. Tasks for the new comer (2):
    15 Apr 2016 - Quartz.NET with RavenDB
  4. Code through the looking glass (5):
    18 Mar 2016 - And a linear search to rule them
  5. Find the bug (8):
    29 Feb 2016 - When you can't rely on your own identity
View all series


Main feed Feed Stats
Comments feed   Comments Feed Stats