I've never really understood the test-first thing in its entirety. In an SOA environment, it seems to me that test-first would put the emphasis on defining interfaces first and building tests against the interface (both good things.) The interface is just an interface. So I wonder if having some of the application logic implemented behind the interface is required to really do test-first right.
It seems to me that some sort of enhancement of agile could help here. One where I build the application and the test at the same time and iteratively.
I am trying this out using an open-source Ajax development framework (Appcelerator) and my test framework (TestMaker.) This is just a bunch of notes right now. I'm hoping to have something coded in the next 2 weeks. Here's how it would work:
Appcelerator uses non-standard tags in HTML to implement Ajax functions. For example:
This provides Appcelerator's function library to a page.
<input type="text" id="username" validator="required" decorator="required" fieldset="login"/>
When the page loads Appcelerator provides Ajax functions for validator, decorator, and fieldset attributes of the <input> tag.
<input type="button" value="login" activators="username,password" id="button"
on="click then r:login.request" fieldset="login"/>
The fieldset attribute is used to link <input> elements (or divs, spans) for the purpose of sending a message. The example above links the username to the submit button. When the user clicks submit the "on" attribute tells Appcelerator to click the submit button and send a login.request message to the server handling the log-in. (Appcelerator implements the server side component and the messaging for you.)
My thought is to extend the tags to include test definition tags. For instance:
<input type="text" id="username" validator="required" decorator="required" fieldset="login" test_input_data="dpl:mycsvfile field:username"/>
<input type="button" value="login" activators="username,password" id="button" on="click then r:login.request" fieldset="login"
In the example above, when the page loads the testmaker.js functions respond to the test_input_data tag by reading from a comma-separated-value (csv) file using a Data Production Library (DPL.) The first row of the csv file defines field titles. TestMaker sets the username input field with the username value in the csv file.
When I want to test the page I use a test runner that loads the page and clicks the login button. The response to the login must be a page with a title of "Main menu". Otherwise, the test throws an exception and I could that as a failed functional test.
What I'm after here is a way to build the tests as we build the application.
I would love your feedback, thoughts, and ideas on this.
From The Cohen Blog