Search the web
Sign In
New User? Sign Up
TestFirstUserInterfaces
? Already a member? Sign in to Yahoo!

Yahoo! Groups Tips

Did you know...
Hear how Yahoo! Groups has changed the lives of others. Take me there.

Best of Y! Groups

   Check them out and nominate your group.
Having problems with message search? Fill out this form to ensure your group is one of the first to be migrated to the new message search system.

Messages

  Messages Help
Advanced
Re: [agile-testing] Unit Testing the Presentation Layer   Message List  
Reply | Forward Message #1047 of 1051 |
Re: [agile-testing] Unit Testing the Presentation Layer

Kaleb Pederson wrote:

> I'm a bit out of my realm as I'm usually strictly backend, but I'm going to
delving into things like this very soon so I've been paying attention to these
topics for a while now.
>
> Still, I'm quite curious exactly what you mean by unit testing the
presentation layer?
>
> Does that imply that you're verifying what the HTML elements, CSS,and Ajax
results are for given calls to the backend? If so, why not test it at the
backend level?

To add a new feature, you should generally add it at the business layer first.
The goal will be that anything a user can do to the View, a unit test can do,
generally the same way, to the business layer.

In the view, don't test the shiny things. Test that your template system has
injected the correct variables. The tests help preserve these behaviors when you
upgrade & refactor, including when you change the shiny things.

> If you're testing mainly what's going on at the front end, it seems like you
could use pure HTML / Javascript to confirm that things act correctly using some
mocked calls to the backend. I guess you could call it a mocked server, but I'm
essentially thinking of a separate facade / interface that doesn't bother with
round-trip calls to a server (even localhost).

JS only works correctly inside a browser. Tests should run under 10 seconds,
from an unattended script. Browsers are not well tuned to be test targets.

Tests on JS should detect that the template systems have injected the correct
data into them. I do this by parsing the JS into a lexical analysis, using
"rkelly", then querying into the resulting parse tree to detect the variables.

> Of course, this doesn't take into account the rendering and cross-browser
compatibility issues, but that's where Selenium Wati(r|n) and friends come into
play.

TDD is not QA testing. At TDD time, we don't need to test that JS commands a
browser correctly, we need to test that our business logic has commanded the JS
correctly. Whether the JS works or not is a different issue.

If the tests constrain JS that does not work, only manual testing will detect a
problem. Programmers should manually test before deploying. If you then upgrade
the JS so it works, the tests should now constrain JS that works. This improves
the odds you don't break the JS when you refactor something.

The systems like Watir that test through the browser are very important, but...

They have provided an entire generation of programmers with an easy entry into
any kind of testing at all. Some projects use no unit tests whatsoever, and they
slowly and painstakingly test everything - including the business logic -
through the View. Some projects have unit tests on the business layers and not
the View.

Of course these tests are better than nothing. Yet in the test food pyramid...

http://c2.com/cgi/wiki?TestFoodPyramid

...a diet of only Watir tests would be like living only on ice cream and beer.
It's fun at first, then the malnutrition begins...

--
Phlip



Fri Jun 12, 2009 2:24 pm

phlipcpp
Offline Offline
Send Email Send Email

Forward
Message #1047 of 1051 |
Expand Messages Author Sort by Date

... Will ASP allow you to cook a web page without sending it over the wire? If you Mock The Server, you can then test - even TDD - by writing assertions that...
Phlip
phlipcpp
Offline Send Email
Jun 12, 2009
2:24 am

... Unit testing the presentation layer should treat the test targets the same as any other layer would test them. In web programming, a web page is a big...
Phlip
phlipcpp
Offline Send Email
Jun 12, 2009
3:48 am

Re: Can ASP render a page back as a string. Absolutely! Its call Response.Write, just pipe it out to whatever channel you like :) Regards, Miguel de Sousa ...
miguel de sousa
migdesousa
Offline Send Email
Jun 12, 2009
4:45 am

... Could anyone here who's familiar with both ASP's Response.Write, and with Rails's ActionController::TestCase's get() method, write a little pseudocode here...
Phlip
phlipcpp
Offline Send Email
Jun 12, 2009
4:49 am

... To add a new feature, you should generally add it at the business layer first. The goal will be that anything a user can do to the View, a unit test can...
Phlip
phlipcpp
Offline Send Email
Jun 12, 2009
2:25 pm

... Here's a metaphor - the Golden Spike at Promontory Point, Utah, where the Union Pacific and Central Pacific railways met for our first intercontinental...
Phlip
phlipcpp
Offline Send Email
Jun 16, 2009
7:05 pm
Advanced

Copyright © 2009 Yahoo! Inc. All rights reserved.
Privacy Policy - Terms of Service - Guidelines - Help