[Seaside] Failing TestCases?

Avi Bryant avi@beta4.com
Tue, 5 Mar 2002 13:35:27 -0800 (PST)


On Tue, 5 Mar 2002, Cees de Groot wrote:

>
> fefr@gmx.net said:
> > I only test the business-logic (using plain unit-tests). In one
> > project  I tried HttpUnit (http://httpunit.sourceforge.net/) to
> > actually test the  generated HTML, but it was too much work to get the
> > test cases right.  Some sort of higher level testing tool would be
> > nice.
>
> Same here, with the difference that we never tried HttpUnit because I
> concluded from a first glance that it wouldn't work ;-). And indeed, all our
> regression bugs are in our .SSP files...
>
> What I've been thinking of is to mark things with special attribute tags
> ("testid=foo") and do some sort of XPath queries with these to find that
> certain table and check whether it has indeed 5 fields.

Yes, that would be cool.  Presumably in Seaside you could do something
with the existing sea:id - it would be trivial to write a macro that
inserted a testid based on this (we've been thinking about doing
something similar for CSS support, incidentally, although I haven't
thought much yet about where you'd want to insert an "id" by default,
where a "class", etc).

The other problem with tools like HttpUnit, though, is that they seem to
assume you have meaningful (and thus predictable) URLs.  Testing a Seaside
application would require a testing framework that could extract the urls
from the current page and use them to test the next one.  Chalk up another
point for statelessness, I'm afraid...

In terms of higher level testing, I experimented with a simple system to
let you interact directly with the page instances, avoiding all the HTML
and HTTP stuff.  Each request is simulated within a "self go: [...]"
block, and the TestCase object makes sure that a "page" instVar is always
set to the current page.  So, an simple test for the calculator example
might look like

self go: [page numberPressed: 1].
self go: [page numberPressed: 0].
self assert: page current = '10'.
self go: [page enter].
self assert: page stack first = 10.
self go: [page current: '20'. page functionPressed: #+].
self assert: page stack first = 30.

I didn't include this code in the release because, due to a strange
interaction between #ensure: and #callCC:, I had to modify SUnit slightly
to get it to work and I haven't tested it enough to be certain I didn't
break anything.  If anyone wants it, I can bring it up to date and post
it.

Avi