; Date: Mon Jul 30 2007
This IBM Developer Works article, In pursuit of code quality: Unit testing Ajax applications came up on my blog crawl today. Andrew Glover says "the emergence of Ajax has essentially invalidated a host of test frameworks and tools that weren't designed to test asynchronous Web applications" and goes on to discuss a methodology to creating unit tests for the GWT application framework.
The approach is to ignore "interaction testing", that is to ignore automation of the interactions with the GUI elements. Instead the approach suggested is to make sure the application is factored with a clean separation of GUI elements and "business logic", and then to test the business logic that's called from the GUI elements.
A similar approach can be taken with any GUI application toolkit. As Andrew says in the article, this is a good approach to building applications in the first place, and it is a recommended best practice to cleanly separate business logic from the UI elements. Doing so makes it easier to refactor the GUI application as your user experience team refines the interactionality of the application.
This second issue, GUI changes that invalidate tests, is something which strongly encourages the recommendation of cleanly separating UI from business logic. One could refactor the GUI all you want, and so long as the business logic doesn't refactor the tests wouldn't change. And, it's clear that in certain parts of the application development process the user experience people must be able to quickly refactor the GUI, try out new ideas, and make refinement after refinement.
I've been helping the Java SE SQE team with test automation for several years now, and one thing I've learned is that the return-on-investment of a test is better the longer you can reuse that test without having to rewrite it. If your test is coded to relatively unchanging interfaces or system attributes it should be reusable for years and years giving great ROI.
Getting back to the question of testing AJAX applications... I think there's approximately four levels to test:
- The server end which provides the datasourcing used by the AJAX app
- The protocol(s) between the AJAX app(s) and the back end(s)
- The business logic inside each of the AJAX app(s)
- The GUI of the AJAX app(s)
But this leaves us with a problem. It leaves out testing one of the application layers. How are you going to validate that the GUI behaves properly? If you don't automate GUI tests, that leaves you with manual GUI testing. As I said earlier the tools for editing GUI interaction with a web browser, they're all commercial testing tools, and they only exist for Windows. If someone knows different please let me know. What this means is there's a likelihood the GUI application will be better tested on Windows than on the other platforms, because the these commercial tools can automate tests there.