76

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.

2

13 Answers 13

35

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.

4
  • Can this be used to automate third party Java applications without access to the source code? If so, how?
    – Stevoisiak
    Oct 6, 2017 at 17:56
  • @StevenVascellaro looks it cannot, anyways +1 for AssertJ Swing
    – emecas
    Dec 7, 2017 at 17:20
  • How are you identifying the object properties. My application under test is a Java Swing UI. How do I get the properties of target fields/buttons that are to be automated? May 1, 2019 at 8:18
  • You can use Testmate to automate Java swing application for free youtu.be/BQQdJ0V23GM
    – Jaskaran
    May 19, 2020 at 6:26
26

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.

6
  • It moves in GitHub from this post. Jul 16, 2013 at 20:27
  • 5
    Fest swing is not being developed any more. It does not support java 7 either. Seems like the swing part of fest is totally dead!
    – user508434
    Apr 7, 2014 at 6:30
  • I use FEST with Swing in Java7 just fine. See github.com/bitcoin-solutions/multibit-hd/tree/develop/… for comprehensive test scenarios
    – Gary
    Apr 2, 2015 at 15:43
  • 1
    The Fest project web site is gone (fest.easytesting.org). The documentation in 2015 is pretty lacking. Is there anything else like it that drives a Swing UI? Jul 1, 2015 at 17:53
  • As someone unfamiliar with JUnit, how can I find and control a Java applet with FEST?
    – Stevoisiak
    Oct 10, 2017 at 19:06
14

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.

0
9

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

1
  • 2
    Jemmy is a very solid framework and we are using it since more than 5 years very successfully.
    – Mot
    Aug 1, 2010 at 15:00
8

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)

2
  • 5
    You say "build your own FWK". What is a FWK? Apr 24, 2010 at 13:07
  • 3
    From my experience, I can say that AWT's Robot is extremely brittle. A major issue is that its low level API is working with absolute coordinates. Tests may break even if your system under test (SUT) hasn't changed (e.g. when executed on another OS).
    – beatngu13
    Jun 25, 2017 at 18:50
7

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

6

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.

4

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."

3

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

1
  • 1
    Note that it is sikulix.com nowadays (still open source)
    – tobi42
    Dec 22, 2015 at 7:06
3

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.

2

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.

0
1

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

1

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.