2

I require to test an application which uses a Swing GUI interface. I have a client/server design and want to simulate client input (from the client's interface) and retrieve the server response.

So far I have looked into jfcUnit and UISpec4J for JDK 7, with use under NetBeans. Attempting to find a named component from the window instance returned nothing using jfcUnit (using the NamedComponentFinder), example comes from here under the login screen example. I assume the name is its string variable name in the class.

The test method I used for searching a client 'Connect' button which gave the empty list result is as follows, where gui is the client gui class(following the rest of the login example above):

 @Test
    public void testConnectVisible () {
        NamedComponentFinder finder = new NamedComponentFinder(JComponent.class, "connectBtn" );
        List allItems = finder.findAll(gui);
        System.out.println(allItems.toString());
    }

Another was UISpec4J, although I can't find a .jar compatible with JDK 7. Its documentation is fuller and would be more suitable.

Does anyone know of a suitable GUI testing framework under JDK 7, or a working example of either of UISpec4J/jfcUnit for JDK 7? I need some way of emulating event-based triggering on the client side.

Edit I would also like to simulate multiple clients, which would require a testing framework that supports several client windows in one test instance.

Many thanks :)

user10941
  • 31
  • 3

1 Answers1

0

In general it is best to not to need to test much in the GUI. Your GUI code should have no business logic in it at all. All of your GUI code should just call code in your business layer.

The code in the business layer is easily testable using normal unit tests. Which will make your GUI tests as few in number as possible.

Having said all of that, many years ago I used a framework called abbot which sounds just like what you need. I just checked their website and it says it should work with Java 7 and tested against java 6.

dkatzel
  • 31,188
  • 3
  • 63
  • 67
  • thank you for your response. As it stands my client code is organised such that all the GUI appearance logic (generated by NetBeans) is separate to the methods which are invoked during action events. Is this what you mean? One testing method I thought of was to include accessors and mutator methods for the necessary interface components, such that I can set text fields and programmatically click buttons etc from a Junit testing class. Does this seem suitable? Using something like abbot might make my code cleaner, I think. – user10941 Jan 10 '14 at 16:09