* Posts by Dan Haywood

1 post • joined 22 Oct 2007

Don't unit test GUIs

Dan Haywood

Naked Objects is a framework that makes testing UIs easy

This isn't an unbiased post because I'm very heavily involved in Naked Objects (http://www.nakedobjects.org), but if you are interested in how to test the business logic behind the UI then this becomes trivially easy when the UI itself is automatically generated from the domain objects (which is what NO is all about).

We're currently reworking the JUnit-based testing framework that ships with Naked Objects, and will be released as a point release in the next month or so (it's currently in our incubator). But to give you a flavour, if one has an action on an object such as Customer#placeOrder which can't be invoked (ie would be greyed out in the UI), then one would write the test as:

try {

proxiedCust.placeOrder(product355, 3);

fail("Should have thrown exception");

} catch(DisabledImperativelyException e) {

assertThat(e.getMessage(), equalTo("cannot invoke"));


String documentText = getInMemoryDocumentor().toString();

assertThat(documentText, equalTo(

"Because the 'Place Order' action is currently disabled (cannot invoke), it cannot be invoked.\n"));

The framework uses a CG-lib proxy to interact with the underlying business object in the same way that the auto-generated UI would. If the placeOrder action is disabled, the proxy throws an exception.

Just thought this might be of interest to you.




Biting the hand that feeds IT © 1998–2021