views:

984

answers:

6

What options are there for building automated tests for GUIs written in Java Swing?

I'd like to test some GUIs which have been written using the NetBeans Swing GUI Builder, so something that works without requiring special tampering of the code under test would be ideal.

+1  A: 

I haven't used it personally, but SwingUnit looks quite good. You can use it with jUnit, and it isn't based on "location of components" (i.e. x and y co-ordinates).

The only thing you may have to do with the NetBeans GUI Builder is set unique names for your components.

Phill Sacre
+7  A: 

I'm currently using FEST. It works with JUnit and will also take screenshots of failed tests.

It has default component hunting methods which look for the name of the component being tested (which need to be set manually), but you can also generate the testers for a given component by passing it the component.

deterb
A: 

We're using QF-Test and are quite satisfied.

ahu
+3  A: 

I use java.awt.Robot. Is not nice, is not easy but works every time.

Pros:

  • You are in control
  • Very fast
  • Build your own FWK
  • Portable
  • No external dependencies

Cons:

  • No nice GUI to build test
  • You have to leave the GUI alone while you test
  • Build your own FWK
  • Difficult to change test code and create your first harness

Now if you have the budget I would go for LoadRunner. Best in class.

(Disclosure: relationship to the company that owns LR, but I worked with LR before the relationship)

Javaxpert
You say "build your own FWK". What is a FWK?
Bryan Oakley
Framework, my guess.
Geoffrey Zheng
+2  A: 

You can try to use Cucumber and Swinger for writing functional acceptance tests in plain english for Swing GUI applications. Swinger uses Netbeans' Jemmy library under the hood to drive the app.

Cucumber allows you to write tests like this:

 Scenario: Dialog manipulation
    Given the frame "SwingSet" is visible
      And the frame "SwingSet" is the container
    When I click the menu "File/About"
    Then I should see the dialog "About Swing!"
    Given the dialog "About Swing!" is the container
    When I click the button "OK"
    Then I should not see the dialog "About Swing!"

Take a look at this Swinger video demo to see it in action.

Dema
+1  A: 

We are considering jemmy to automate some of the GUI testing. Looks promising.

Jayan
Jemmy is a very solid framework and we are using it since more than 5 years very successfully.
mklhmnn