Ayende @ Rahien

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

ayende@ayende.com

+972 52-548-6969

, @ Q c

Posts: 5,969 | Comments: 44,491

filter by tags archive

Presentation Logic & Semi Integration Tests


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.


Comments

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".

Later.

--scott

Comment preview

Comments have been closed on this topic.

FUTURE POSTS

No future posts left, oh my!

RECENT SERIES

  1. Production postmortem (5):
    29 Jul 2015 - The evil licensing code
  2. Career planning (6):
    24 Jul 2015 - The immortal choices aren't
  3. API Design (7):
    20 Jul 2015 - We’ll let the users sort it out
  4. What is new in RavenDB 3.5 (3):
    15 Jul 2015 - Exploring data in the dark
  5. The RavenDB Comic Strip (3):
    28 May 2015 - Part III – High availability & sleeping soundly
View all series

RECENT COMMENTS

Syndication

Main feed Feed Stats
Comments feed   Comments Feed Stats