I've got a fair amount of experience using httpunit to do front end
testing. it's not for the faint of heart, and with more and more ajax,
frankly it's just not really a viable option anymore as its javascript
support seems not to be up to the challenge. I don't believe httpunit
is being supported anymore and so I don't think that problem is going
to improve. I really, really like it, but I fear its time may have
passed.
At my former job, we had a small group whose sole purpose was "testing
technologies". I know they settled on mercury test director and astra
quicktest, and those worked well for them, although that was 4 or 5
years ago.
Seems like the bigguns now are selenium, canoo, and watir. at least,
those are the ones i hear a lot about. Bill and Rankin, you guys have
played pretty extensively with canoo, right?
I'd really love to see this discussion go somewhere because word on
the street where i work is that, finally, after years of ignoring the
need for it, it looks like we might finally start doing some kind of
automated front-end testing and I want to be sure that the group doing
this knows all their options.
great topic, Andrew.
marc
1) I think rather than thinking about testing the UI you are concerned with the database data a particular method returns that eventually drives the UI.
So I think this is still a job for the unit test. You will want to assert the method returns a query and that data in the returned rows is what you expect.
2) As its data you're really testing you want data you can trust for the tests. And you either set up a test database that has static reliable data for testing or you add some stuff to the test cases that loads the data before doing the tests on it.
But then maybe this is a bad idea if the purpose of your test is to check the live data :-)
I haven't looked into DBunit yet but would it be a big job to have a dbunit-esque extension to mxUnit?
Alan
________________________________________
From: mxu...@googlegroups.com [mxu...@googlegroups.com] On Behalf Of Andrew Bialecki [andrew....@gmail.com]
Sent: 28 April 2008 00:37
To: mxunit
Subject: [mxunit:333] Using TDD, what are best practices for testing the front end?
Tests should be repeatable and independent, so for any test that
depends on the db state, you're going to have to have an automated
tool for putting the db into a known state. I'm working on something
like dbUnit (it isn't a port as I don't love their API, but solves
similar class of problems) and I'll throw it over to Marc and Bill
once I'm done with it for their input. I'm not convinced it should be
part of MX Unit in the same way as DB Unit is a separate project to
JUnit, but I don't really mind either way. I need the code to scratch
my own itch, but I don't need another OSS project to manage, so no
doubt if anyone finds value in it a home will be found for the code
somewhere.
Additional thoughts re: the testing:
- Acceptance test via wattir/selenium. You'll need to put the db in a
known state before running the tests.
- Unit test the model API, mocking out db access for quick tests that
it does the right stuff with data without having to call the db (which
is slow)
- Unit test the db access code (again, you'll need something like db
Unit) - these tests will run slow so may be run less often
- Unit test controller, mocking out the model to ensure it handles its
responsibilities correctly.
- Consider using a View/Presenter pattern so if there is anything non-
trivial in the view that needs tested it can be unit tested via
testing view helpers/presenters.
- There are also various frameworks for making assertions against the
DOM which you may want to check out, but I've not had a chance to play
with them yet.
Best Wishes,
Peter
Best Wishes,
Peter
The upside is that it lets you keep private stuff private that should
be private. The downside is that you create the potential for a bit of
brittleness in your tests because you now have a test that would break
should you decided to refactor out that private method in question.
My opinion on that reservation is "who cares, i'll just delete the
test".
anyway, it's there if you need it.
marc
Best Wishes,
Peter
<cffunction name="demoFail2">
<cfset obj = createObject("component","myObject")>
<cftry>
<cfset IWishThisWouldPassButItWont =
obj.PayMarc5MillionToDrinkDalwhinnie15AllDayLong()>
<cfset fail("Should not get here. Function under test should've
thrown an error because I can't find someone to pay me lots of money
to drink great scotch")>
<cfcatch type="mxunit.exception.AssertionFailedError">
<cfrethrow>
</cfcatch>
<cfcatch type="any"><!--- expect to get here ---></cfcatch>
</cftry>
</cffunction>
this kind of verbosity, although currently required, drives me nuts.
it will be dealt with after we release 1.0 (shortly).
so, bottom line, have a catch that looks for an
mxunit.exception,AssertionFailedError and rethrow if it gets there.
just in case you didnt' know, on cfsnippets.org there's an mxunit
package that contains this as an example. i personally have a snippet
in my snip tree that has a stub for this, with a keyboard trigger of
"testerror", and it creates the boilerplate junk for me so I can focus
on the stuff between the cftry and the first catch block. not ideal,
i know, but it saves a few keystrokes.