Automated tests for Java Swing GUIs

JavaSwingTestingAutomated Tests

Java Problem Overview


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.

Java Solutions


Solution 1 - Java

Recently I came across FEST which seemed promising, except that the developer announced in 2012 that development would not continue.

AssertJ is a fork of FEST that is working very well for me. It is actively maintained (at time of writing), supports Java 8, has assertions for a few popular libraries such as Guava and Joda Time, and is very well documented. It is also free and open.

Solution 2 - Java

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.

Solution 3 - Java

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.

Solution 4 - Java

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

Solution 5 - Java

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)

Solution 6 - Java

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

Solution 7 - Java

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.

Solution 8 - Java

You can use Marathon : "Marathon Integrated Testing Environment, MarathonITE, is an affordable, easy-to-use and cross-platform Java/Swing™ GUI Test automation framework. You can use MarathonITE‘s inbuilt script recorder to create clean, readable test scripts either in Python or Ruby. Advanced features like extract-method refactoring, create-datadriven-tests and objectmap editing allows you to create maintainable, resilient test suites."

Solution 9 - Java

Sikuli: a GUI-tester using screenshots http://sikuli.org/

Solution 10 - Java

You could try ReTest, which is a novel tool that implements an innovative approach to functional regression testing and combines it with ai-based monkey testing. It is about to become open source as well...

Disclaimer: I am one of the founders of the company behind ReTest.

Solution 11 - Java

For those with an adventurous mind, there is gooey <https://github.com/robertoaflores/Gooey> a (very basic and under-development) programmatic testing tool for swing applications.

Solution 12 - Java

Just did some quick scans. Squish was the most promising. Not for free though

Solution 13 - Java

You can user sikuli or Automa for testing your GUI part, these are well documented and tested tools

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionpauldooView Question on Stackoverflow
Solution 1 - JavaJwest08View Answer on Stackoverflow
Solution 2 - JavadeterbView Answer on Stackoverflow
Solution 3 - JavaDemaView Answer on Stackoverflow
Solution 4 - JavaJayanView Answer on Stackoverflow
Solution 5 - JavaJavaxpertView Answer on Stackoverflow
Solution 6 - JavaahuView Answer on Stackoverflow
Solution 7 - Javauser7094View Answer on Stackoverflow
Solution 8 - JavaHashanView Answer on Stackoverflow
Solution 9 - JavaViktor MellgrenView Answer on Stackoverflow
Solution 10 - JavaroesslerjView Answer on Stackoverflow
Solution 11 - JavaRoberto FloresView Answer on Stackoverflow
Solution 12 - JavaamutterView Answer on Stackoverflow
Solution 13 - JavaSanjit Kumar MishraView Answer on Stackoverflow