1

I am building a simple Swing based Java application and would like to add some simple end-to-end tests. I have come across the UISpec4J library and imported it into my Maven project like this:

<dependency>
    <groupId>org.uispec4j</groupId>
    <artifactId>uispec4j</artifactId>
    <version>2.4</version>
    <scope>test</scope>
</dependency>

I also have the following Main class:

public class Main
{
    public static void main(String[] args)
    {
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                MainWindow window = new MainWindow();
                window.setLocationRelativeTo(null);
                window.setVisible(true);
            }
        });
    }
}

There does not seem to be a lot of materials about UISpec4J available on the Internet but according to a few tutorials that I managed to find the following code should work:

public class CanFillInABasicFormTest extends UISpecTestCase
{
    @BeforeClass
    public void setUp() {
        setAdapter(new MainClassAdapter(Main.class, new String[0]));
    }

    @Test
    public void test() 
    {
        Window mainWindow = getMainWindow();
    }
}

But instead it fails with the following exception:

java.lang.AbstractMethodError: org.uispec4j.interception.toolkit.UISpecToolkit.createKeyboardFocusManagerPeer(Ljava/awt/KeyboardFocusManager;)Ljava/awt/peer/KeyboardFocusManagerPeer;
    at java.awt.KeyboardFocusManager.initPeer(Unknown Source)
    at java.awt.KeyboardFocusManager.<init>(Unknown Source)
    at java.awt.DefaultKeyboardFocusManager.<init>(Unknown Source)
    at java.awt.KeyboardFocusManager.getCurrentKeyboardFocusManager(Unknown Source)
    at java.awt.KeyboardFocusManager.getCurrentKeyboardFocusManager(Unknown Source)
    at javax.swing.UIManager.initialize(Unknown Source)
    at javax.swing.UIManager.maybeInitialize(Unknown Source)
    at javax.swing.UIManager.getDefaults(Unknown Source)
    at javax.swing.UIManager.put(Unknown Source)
    at org.uispec4j.interception.ui.UISpecLF.init(UISpecLF.java:11)
    at org.uispec4j.UISpec4J.init(UISpec4J.java:32)
    at org.uispec4j.UISpecTestCase.<clinit>(UISpecTestCase.java:31)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    at junit.framework.TestSuite.createTest(TestSuite.java:61)
    at junit.framework.TestSuite.addTestMethod(TestSuite.java:294)
    at junit.framework.TestSuite.addTestsFromTestCase(TestSuite.java:150)
    at junit.framework.TestSuite.<init>(TestSuite.java:129)
    at org.junit.internal.runners.JUnit38ClassRunner.<init>(JUnit38ClassRunner.java:71)
    at org.junit.internal.builders.JUnit3Builder.runnerForClass(JUnit3Builder.java:14)
    at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:57)
    at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:29)
    at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:57)
    at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:24)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.<init>(JUnit4TestReference.java:33)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestClassReference.<init>(JUnit4TestClassReference.java:25)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createTest(JUnit4TestLoader.java:48)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.loadTests(JUnit4TestLoader.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:452)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

What am I doing wrong? Also, the UISpec4J library is the first one that Google recommended to me but I am opened for suggestions to other functional testing libraries as well.

Roman C
  • 49,761
  • 33
  • 66
  • 176
Dušan Rychnovský
  • 11,699
  • 8
  • 41
  • 65

2 Answers2

3

Switching to jdk1.6 update 0 worked for me. I was using jdk1.7 and I got the same error.

Moreover, I think that annotations are not necessary, because you are using junit3 (extending UISpecTestCase, that extends TestCase)

public class CanFillInABasicFormTest extends UISpecTestCase {
    public void setUp() {
        setAdapter(new MainClassAdapter(Main.class, new String[0]));
    }

    public void test() {
        Window mainWindow = getMainWindow();
    }
}
Giuseppe Galano
  • 10,412
  • 1
  • 12
  • 10
  • did you just run via jdk1.6 or changed JAVA_HOME too? Switching to jdk1.6 gave me Exception in thread "main" java.lang.UnsupportedClassVersionError: uispec4j/HealthIndicatorsProModeTest : Unsupported major.minor version 51.0 – bgplaya Oct 24 '14 at 10:04
1

Problem is in class org.uispec4j.interception.toolkit.UISpecToolkit which was created before java 1.7. Class UISpecToolkit implements abstract class org.uispec4j.interception.toolkit.ToolkitDelegate. ToolkitDelegate extends another abstract class SunToolkit. Class SunToolkit is root of problems. In Java 1.7 there is a new abstract method:

KeyboardFocusManagerPeer sun.awt.SunToolkit.getKeyboardFocusManagerPeer()

This method is not implemented in class UISpecToolkit. In SunToolkit in Java 1.7 is also new method:

protected abstract boolean syncNativeQueue(final long timeout);

It's not possible to easily add new implementation of this SunToolkit to uispec4j. So without new library release or some non trivial effort it's not possible to use uispec4j library at java 1.7.

Jan
  • 15
  • 5