Hi Shannon,
I wouldn't be the first to say this, but testing generated HTML is a
pain, especially volatile content. Still, there's a need. Your
approach would certainly work, but may be hard to maintain down the
road. You may want something more fine grained like assertXPath()
which addresses testing HTML (and XML). Check out the docs here and
scroll down:
http://wiki.mxunit.org/display/default/Built-In+Assertions
Basically, it's this:
assertXPath(String xpath, any data, [String text], [String message])
where 'data' is any string or URL (http:// or file://). So, there
should be enough flexibility there to test HTML, if it's reasonably
well formed. Others on the list have much more experience with testing
custom tags, and I hope they might chime in, too.
Another_ completely_ different approach I've been discussing with
someone at work, is using some kind of a checksum. Now, this is may
seem odd, but bear with me. Essentially, a checksum could be computed
from certain critical portions of the page and then embedded in an
easy to find HTML comment. As you are rendering a page, you could
collect various values that you deem important and once collected
successfully, hash them and embed that in the page. In your test, you
take the generated content and locate the checksum.
Example (assuming database is in a stable state):
<cfoutput query="q">
<cfset variables.collected +=
q.id />
<div id="#
q.id#">#
q.name#</div>
</cfoutput>
...somewhere else on the page, like the bottom...
<cfset variables.checksum = hash(variables.collected) />
<cfoutput>
<!--@checksum=#variables.checksum#-->
</cfoutput>
Then in your test, you could use a regular expression to extract the
@checksum value and compare that to your actual value. The idea is
that the checksum would only be generated if the page successfully
rendered. It wouldn't get the whole page or every element, of course,
but might be a decent barometer.
best,
bill
On Jul 22, 6:12 pm, Shannon <
smho...@gmail.com> wrote:
> I found an example of how to test the content of a CFM file or
> cfinclude in the article "Test Driven Development with Coldfusion Part
> II: Building Unit Tests for CFUnit" found herehttp://
www.fusionauthority.com/techniques/4568-test-driven-developmen...,