uispec4j测试应用程序java

时间:2012-09-09 15:13:00

标签: java testing uispec4j

我有一个小应用程序,电话簿,我想测试它。 我对uispec4j有一些问题,我写这个:

public class TestRubricaBlack extends UISpecTestCase{

@BeforeClass
public void setUp(){
    setAdapter(new MainClassAdapter(Rubrica.class, new String[0]));

}

public void testMamma(){

    Window window=getMainWindow();
    assertEquals(true,window.getButton("index").isVisible());
}
}

当我尝试执行测试时,我有这个错误,问题出在函数getMainWindow()上:

java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
    at org.uispec4j.utils.TriggerRunner.runInCurrentThread(TriggerRunner.java:18)
    at org.uispec4j.interception.WindowInterceptor.run(WindowInterceptor.java:320)
    at org.uispec4j.interception.WindowInterceptor.run(WindowInterceptor.java:290)
    at org.uispec4j.interception.MainClassAdapter.getMainWindow(MainClassAdapter.java:24)
    at org.uispec4j.UISpecTestCase.getMainWindow(UISpecTestCase.java:84)
    at it.is2.TestRubricaBlack.testMamma(TestRubricaBlack.java:31)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at junit.framework.TestCase.runTest(TestCase.java:168)
    at junit.framework.TestCase.runBare(TestCase.java:134)
    at junit.framework.TestResult$1.protect(TestResult.java:110)
    at junit.framework.TestResult.runProtected(TestResult.java:128)
    at junit.framework.TestResult.run(TestResult.java:113)
    at junit.framework.TestCase.run(TestCase.java:124)
    at junit.framework.TestSuite.runTest(TestSuite.java:243)
    at junit.framework.TestSuite.run(TestSuite.java:238)
    at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:83)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
    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)
Caused by: java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.uispec4j.utils.MainClassTrigger.run(MainClassTrigger.java:22)
    at org.uispec4j.utils.TriggerRunner.runInCurrentThread(TriggerRunner.java:12)
    ... 24 more
Caused by: java.lang.NullPointerException: peer
    at sun.awt.windows.WTextFieldPeer.create(Native Method)
    at sun.awt.windows.WComponentPeer.<init>(WComponentPeer.java:595)
    at sun.awt.windows.WTextComponentPeer.<init>(WTextComponentPeer.java:36)
    at sun.awt.windows.WTextFieldPeer.<init>(WTextFieldPeer.java:65)
    at sun.awt.windows.WToolkit.createTextField(WToolkit.java:332)
    at org.uispec4j.interception.toolkit.ToolkitDelegate.createTextField(ToolkitDelegate.java:262)
    at java.awt.TextField.addNotify(TextField.java:205)
    at java.awt.Container.addNotify(Container.java:2592)
    at javax.swing.JComponent.addNotify(JComponent.java:4683)
    at java.awt.Container.addNotify(Container.java:2592)
    at javax.swing.JComponent.addNotify(JComponent.java:4683)
    at java.awt.Container.addNotify(Container.java:2592)
    at javax.swing.JComponent.addNotify(JComponent.java:4683)
    at java.awt.Container.addNotify(Container.java:2592)
    at javax.swing.JComponent.addNotify(JComponent.java:4683)
    at javax.swing.JRootPane.addNotify(JRootPane.java:735)
    at java.awt.Container.addNotify(Container.java:2592)
    at java.awt.Window.addNotify(Window.java:638)
    at java.awt.Frame.addNotify(Frame.java:469)
    at java.awt.Window.show(Window.java:823)
    at it.is2.Rubrica.main(Rubrica.java:26)
    ... 30 more
有人能帮帮我吗? 提前致谢

1 个答案:

答案 0 :(得分:0)

堆栈跟踪告诉我找不到名为“index”的按钮。不是精神上的或者你的代码可用,我不知道为什么。以下是我最好的猜测:

  1. 您没有定义名为“index”的按钮
  2. 你错了名字
  3. 按钮在面板上定义,而不是直接在主窗口上定义
  4. 我遇到第三项问题,这就是我遇到你的帖子的方式。我可能错了,但似乎uispec4j不会自动查看像面板这样的容器,在我的例子中,JScrollPanes。

    如果我发现我对此行为有误,我会更新我的回复。如果我想出一个解决方案,也许是一个自定义匹配器,我也会发布它。

    祝你好运。