我正在构建一个简单的基于 Swing 的 Java 应用程序,并想添加一些简单的端到端测试。我遇到了UISpec4J库并将其导入到我的 Maven 项目中,如下所示:
<dependency>
<groupId>org.uispec4j</groupId>
<artifactId>uispec4j</artifactId>
<version>2.4</version>
<scope>test</scope>
</dependency>
我还有以下主要课程:
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);
}
});
}
}
互联网上似乎没有很多关于 UISpec4J 的材料,但根据我设法找到的一些教程,以下代码应该可以工作:
public class CanFillInABasicFormTest extends UISpecTestCase
{
@BeforeClass
public void setUp() {
setAdapter(new MainClassAdapter(Main.class, new String[0]));
}
@Test
public void test()
{
Window mainWindow = getMainWindow();
}
}
但相反,它失败了,但出现以下异常:
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)
我究竟做错了什么?此外,UISpec4J 库是 Google 向我推荐的第一个库,但我也愿意向其他功能测试库提出建议。