如何配置GWTTestCase扩展类

时间:2013-01-02 09:01:12

标签: unit-testing gwt testing junit gwttestcase

我想为我创建的GWT复合组件编写测试用例,我有一个扩展com.google.gwt.user.client.ui.Composite的类Count,在此我有一个文本框和一些处理程序根据值显示标签。

现在我想为这个类编写测试用例, 我尝试下面的代码,但它总是显示相同的错误:java.lang.NoSuchMethodError:org.mortbay.thread.Timeout。(Ljava / lang / Object;)V

我的代码是:

    package com.rubirules.uibuilder.client;
import org.junit.Test;
import com.google.gwt.junit.client.GWTTestCase;
public class CountTest extends GWTTestCase {
    @Override
    public String getModuleName() {
        return "com.rubirules.uibuilder.client.Count";
    }
    @Test
    public void testNullConstructor(){  
            assertFalse(true);
                        //TODO need to add some code to test Count class
    }
}

我也想知道getModuleName()方法有什么用?我给了我班上的字符串路径。

完成错误消息是:

java.lang.NoSuchMethodError: org.mortbay.thread.Timeout.<init>(Ljava/lang/Object;)V
    at org.mortbay.io.nio.SelectorManager$SelectSet.<init>(SelectorManager.java:306)
    at org.mortbay.io.nio.SelectorManager.doStart(SelectorManager.java:223)
    at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:39)
    at org.mortbay.jetty.nio.SelectChannelConnector.doStart(SelectChannelConnector.java:303)
    at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:39)
    at org.mortbay.jetty.Server.doStart(Server.java:233)
    at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:39)
    at com.google.gwt.dev.shell.jetty.JettyLauncher.start(JettyLauncher.java:672)
    at com.google.gwt.dev.DevMode.doStartUpServer(DevMode.java:509)
    at com.google.gwt.dev.DevModeBase.startUp(DevModeBase.java:1093)
    at com.google.gwt.junit.JUnitShell.getUnitTestShell(JUnitShell.java:707)
    at com.google.gwt.junit.JUnitShell.runTest(JUnitShell.java:652)
    at com.google.gwt.junit.client.GWTTestCase.runTest(GWTTestCase.java:441)
    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 com.google.gwt.junit.client.GWTTestCase.run(GWTTestCase.java:296)
    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)
   [WARN] failed SelectChannelConnector@0.0.0.0:0
java.lang.NoSuchMethodError: org.mortbay.thread.Timeout.<init>(Ljava/lang/Object;)V
    at org.mortbay.io.nio.SelectorManager$SelectSet.<init>(SelectorManager.java:306)
    at org.mortbay.io.nio.SelectorManager.doStart(SelectorManager.java:223)
    at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:39)
    at org.mortbay.jetty.nio.SelectChannelConnector.doStart(SelectChannelConnector.java:303)
    at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:39)
    at org.mortbay.jetty.Server.doStart(Server.java:233)
    at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:39)
    at com.google.gwt.dev.shell.jetty.JettyLauncher.start(JettyLauncher.java:672)
    at com.google.gwt.dev.DevMode.doStartUpServer(DevMode.java:509)
    at com.google.gwt.dev.DevModeBase.startUp(DevModeBase.java:1093)
    at com.google.gwt.junit.JUnitShell.getUnitTestShell(JUnitShell.java:707)
    at com.google.gwt.junit.JUnitShell.runTest(JUnitShell.java:652)
    at com.google.gwt.junit.client.GWTTestCase.runTest(GWTTestCase.java:441)
    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 com.google.gwt.junit.client.GWTTestCase.run(GWTTestCase.java:296)
    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)
   [WARN] failed Server@2edfcb
java.lang.NoSuchMethodError: org.mortbay.thread.Timeout.<init>(Ljava/lang/Object;)V
    at org.mortbay.io.nio.SelectorManager$SelectSet.<init>(SelectorManager.java:306)
    at org.mortbay.io.nio.SelectorManager.doStart(SelectorManager.java:223)
    at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:39)
    at org.mortbay.jetty.nio.SelectChannelConnector.doStart(SelectChannelConnector.java:303)
    at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:39)
    at org.mortbay.jetty.Server.doStart(Server.java:233)
    at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:39)
    at com.google.gwt.dev.shell.jetty.JettyLauncher.start(JettyLauncher.java:672)
    at com.google.gwt.dev.DevMode.doStartUpServer(DevMode.java:509)
    at com.google.gwt.dev.DevModeBase.startUp(DevModeBase.java:1093)
    at com.google.gwt.junit.JUnitShell.getUnitTestShell(JUnitShell.java:707)
    at com.google.gwt.junit.JUnitShell.runTest(JUnitShell.java:652)
    at com.google.gwt.junit.client.GWTTestCase.runTest(GWTTestCase.java:441)
    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 com.google.gwt.junit.client.GWTTestCase.run(GWTTestCase.java:296)
    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)

2 个答案:

答案 0 :(得分:1)

我建议您使用gwt-test-utils,它有完整的文档和samples

答案 1 :(得分:1)

请检查Google GWT团队如何为小部件编写测试用例。您可以在google gwt trunk代码中查看它们 - http://code.google.com/p/google-web-toolkit/source/browse/trunk/user/test/com/google/gwt/user/client/ui

使用评论回复编辑:

更改getModuleName()返回字符串以反映gwt模块文件的路径 com.rubirules.uibuilder.UIbuilder