Build Tests While Building Applications
Join the DZone community and get the full member experience.
Join For FreeI'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:
<script src="javascripts/appcelerator.js"
type="text/javascript"></script>
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.)
This kind of tag framework approach to application composition and development is wide spread and makes application development easier. In the above example, I didn't have to do any JavaScript work to deliver an Ajax enabled log-in page.
My thought is to extend the tags to include test definition tags. For instance:
<script src="javascripts/testmaker.js" type="text/javascript"></script>
<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"
test_verify="verifyTitle:Main menu"
/>
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.
-Frank
From The Cohen BlogĀ
Opinions expressed by DZone contributors are their own.
Comments