随着我的应用程序扩展,我决定应用JUnit测试,因此我可以阻止NullPointerException 尽可能多地特别是在Activity&放置以及RequestFactory。
但是,我试图在ClientFactory上执行测试,我已经能够将参数传递给JUnit,就像 followijng:
gwt.test.jvmargs = -Xmx256M -Dgwt.args =“ - testBeginTimeout 5”-Dgwt.args =“ - prod”-Dgwt.args =“ - runStyle Manual:1”
当我运行测试时,我收到InternalCompilerException。下面是错误堆栈:
Validating newly compiled units
[ERROR] Errors in 'jar:file:/D:/gwt-2.1.1/gwt-user.jar!/com/google/gwt/logging/client/LogConfiguration.java'
[ERROR] Line 77: The method addHandler(Handler) is undefined for the type Logger
[ERROR] Failed to create an instance of 'com.google.gwt.junit.client.impl.JUnitHost' via deferred binding
com.google.gwt.dev.jjs.InternalCompilerException: Unexpected error during visit.
at com.google.gwt.dev.js.ast.JsVisitor.translateException(JsVisitor.java:466)
at com.google.gwt.dev.js.ast.JsVisitor.doTraverse(JsVisitor.java:452)
at com.google.gwt.dev.js.ast.JsVisitor.doAccept(JsVisitor.java:423)
at com.google.gwt.dev.js.ast.JsVisitor.accept(JsVisitor.java:98)
at com.google.gwt.dev.js.JsToStringGenerationVisitor.visit(JsToStringGenerationVisitor.java:667)
at com.google.gwt.dev.shell.Jsni$JsSourceGenWithJsniIdentFixup.visit(Jsni.java:224)
at com.google.gwt.dev.js.ast.JsInvocation.traverse(JsInvocation.java:64)
at com.google.gwt.dev.js.ast.JsVisitor.doTraverse(JsVisitor.java:450)
at com.google.gwt.dev.js.ast.JsVisitor.doAccept(JsVisitor.java:423)
at com.google.gwt.dev.js.ast.JsVisitor.accept(JsVisitor.java:98)
at com.google.gwt.dev.shell.Jsni$JsSourceGenWithJsniIdentFixup.visit(Jsni.java:219)
at com.google.gwt.dev.js.ast.JsInvocation.traverse(JsInvocation.java:64)
at com.google.gwt.dev.js.ast.JsVisitor.doTraverse(JsVisitor.java:450)
at com.google.gwt.dev.js.ast.JsVisitor.doAccept(JsVisitor.java:423)
at com.google.gwt.dev.js.ast.JsVisitor.accept(JsVisitor.java:98)
at com.google.gwt.dev.js.JsToStringGenerationVisitor.visit(JsToStringGenerationVisitor.java:286)
at com.google.gwt.dev.js.ast.JsArrayAccess.traverse(JsArrayAccess.java:72)
at com.google.gwt.dev.js.ast.JsVisitor.doTraverse(JsVisitor.java:450)
at com.google.gwt.dev.js.ast.JsVisitor.doAccept(JsVisitor.java:423)
at com.google.gwt.dev.js.ast.JsVisitor.accept(JsVisitor.java:98)
at com.google.gwt.dev.js.JsToStringGenerationVisitor.visit(JsToStringGenerationVisitor.java:311)
at com.google.gwt.dev.js.ast.JsBinaryOperation.traverse(JsBinaryOperation.java:108)
at com.google.gwt.dev.js.ast.JsVisitor.doTraverse(JsVisitor.java:450)
at com.google.gwt.dev.js.ast.JsVisitor.doAccept(JsVisitor.java:423)
at com.google.gwt.dev.js.ast.JsVisitor.accept(JsVisitor.java:98)
at com.google.gwt.dev.js.JsToStringGenerationVisitor.visit(JsToStringGenerationVisitor.java:509)
at com.google.gwt.dev.js.ast.JsExprStmt.traverse(JsExprStmt.java:37)
at com.google.gwt.dev.js.ast.JsVisitor.doTraverse(JsVisitor.java:450)
at com.google.gwt.dev.js.ast.JsVisitor.doAccept(JsVisitor.java:423)
at com.google.gwt.dev.js.ast.JsVisitor.accept(JsVisitor.java:98)
at com.google.gwt.dev.js.JsToStringGenerationVisitor.printJsBlock(JsToStringGenerationVisitor.java:1002)
at com.google.gwt.dev.js.JsSourceGenerationVisitor.visit(JsSourceGenerationVisitor.java:48)
at com.google.gwt.dev.js.ast.JsBlock.traverse(JsBlock.java:43)
at com.google.gwt.dev.js.ast.JsVisitor.doTraverse(JsVisitor.java:450)
at com.google.gwt.dev.js.ast.JsVisitor.doAccept(JsVisitor.java:423)
at com.google.gwt.dev.js.ast.JsVisitor.accept(JsVisitor.java:98)
at com.google.gwt.dev.shell.Jsni.generateJavaScriptForHostedMode(Jsni.java:255)
at com.google.gwt.dev.shell.Jsni.getJavaScriptForHostedMode(Jsni.java:242)
at com.google.gwt.dev.shell.ModuleSpaceOOPHM.createNativeMethods(ModuleSpaceOOPHM.java:49)
at com.google.gwt.dev.shell.CompilingClassLoader.injectJsniMethods(CompilingClassLoader.java:1215)
at com.google.gwt.dev.shell.CompilingClassLoader.findClass(CompilingClassLoader.java:1039)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
at com.google.gwt.junit.client.impl.JUnitHost_Proxy.<clinit>(JUnitHost_Proxy.java:15)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:247)
at com.google.gwt.dev.shell.ModuleSpace.loadClassFromSourceName(ModuleSpace.java:654)
at com.google.gwt.dev.shell.ModuleSpace.rebindAndCreate(ModuleSpace.java:458)
at com.google.gwt.dev.shell.GWTBridgeImpl.create(GWTBridgeImpl.java:49)
at com.google.gwt.core.client.GWT.create(GWT.java:97)
at com.google.gwt.junit.client.impl.GWTRunner.<init>(GWTRunner.java:184)
at com.google.gwt.junit.client.impl.GWTRunnerImplgecko1_8.<init>(GWTRunnerImplgecko1_8.java:6)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at com.google.gwt.dev.shell.ModuleSpace.rebindAndCreate(ModuleSpace.java:465)
at com.google.gwt.dev.shell.ModuleSpace.onLoad(ModuleSpace.java:375)
at com.google.gwt.dev.shell.OophmSessionHandler.loadModule(OophmSessionHandler.java:183)
at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:510)
at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:352)
at java.lang.Thread.run(Thread.java:619)
Caused by: java.lang.SecurityException: Prohibited package name: java.io
at java.lang.ClassLoader.preDefineClass(ClassLoader.java:479)
at java.lang.ClassLoader.defineClass(ClassLoader.java:614)
at java.lang.ClassLoader.defineClass(ClassLoader.java:465)
at com.google.gwt.dev.shell.CompilingClassLoader.findClass(CompilingClassLoader.java:1011)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:247)
at com.google.gwt.dev.shell.CompilingClassLoader$DispatchClassInfoOracle.getClassFromBinaryName(CompilingClassLoader.java:236)
at com.google.gwt.dev.shell.CompilingClassLoader$DispatchClassInfoOracle.getClassFromBinaryOrSourceName(CompilingClassLoader.java:266)
at com.google.gwt.dev.shell.CompilingClassLoader$DispatchClassInfoOracle.getClassInfoFromClassName(CompilingClassLoader.java:288)
at com.google.gwt.dev.shell.CompilingClassLoader$DispatchClassInfoOracle.getDispId(CompilingClassLoader.java:146)
at com.google.gwt.dev.shell.CompilingClassLoader.getDispId(CompilingClassLoader.java:930)
at com.google.gwt.dev.shell.Jsni$JsSourceGenWithJsniIdentFixup.visit(Jsni.java:105)
at com.google.gwt.dev.js.ast.JsNameRef.traverse(JsNameRef.java:121)
at com.google.gwt.dev.js.ast.JsVisitor.doTraverse(JsVisitor.java:450)
... 61 more
[ERROR] Failed to create an instance of 'com.google.gwt.junit.client.impl.GWTRunner' via deferred binding
java.lang.RuntimeException: Deferred binding failed for 'com.google.gwt.junit.client.impl.JUnitHost' (did you forget to inherit a required module?)
at com.google.gwt.dev.shell.GWTBridgeImpl.create(GWTBridgeImpl.java:53)
at com.google.gwt.core.client.GWT.create(GWT.java:97)
at com.google.gwt.junit.client.impl.GWTRunner.<init>(GWTRunner.java:184)
at com.google.gwt.junit.client.impl.GWTRunnerImplgecko1_8.<init>(GWTRunnerImplgecko1_8.java:6)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at com.google.gwt.dev.shell.ModuleSpace.rebindAndCreate(ModuleSpace.java:465)
at com.google.gwt.dev.shell.ModuleSpace.onLoad(ModuleSpace.java:375)
at com.google.gwt.dev.shell.OophmSessionHandler.loadModule(OophmSessionHandler.java:183)
at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:510)
at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:352)
at java.lang.Thread.run(Thread.java:619)
Caused by: com.google.gwt.core.ext.UnableToCompleteException: (see previous log entries)
at com.google.gwt.dev.shell.ModuleSpace.rebindAndCreate(ModuleSpace.java:503)
at com.google.gwt.dev.shell.GWTBridgeImpl.create(GWTBridgeImpl.java:49)
... 13 more
[ERROR] Unable to load module entry point class com.google.gwt.junit.client.impl.GWTRunner (see associated exception for details)
com.google.gwt.core.ext.UnableToCompleteException: (see previous log entries)
at com.google.gwt.dev.shell.ModuleSpace.rebindAndCreate(ModuleSpace.java:503)
at com.google.gwt.dev.shell.ModuleSpace.onLoad(ModuleSpace.java:375)
at com.google.gwt.dev.shell.OophmSessionHandler.loadModule(OophmSessionHandler.java:183)
at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:510)
at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:352)
at java.lang.Thread.run(Thread.java:619)
[ERROR] Failed to load module 'org.opevel.projectname.JUnit' from user agent 'Mozilla/5.0 (Windows; U; Windows NT 5.2; en-US; rv:1.9.1.19) Gecko/20110420 Firefox/3.5.19 GTB7.1' at localhost:2034
com.google.gwt.core.ext.UnableToCompleteException: (see previous log entries)
at com.google.gwt.dev.shell.ModuleSpace.onLoad(ModuleSpace.java:434)
at com.google.gwt.dev.shell.OophmSessionHandler.loadModule(OophmSessionHandler.java:183)
at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:510)
at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:352)
at java.lang.Thread.run(Thread.java:619)
会感激一些帮助。
此致
答案 0 :(得分:0)
GWT命令行工具公开的测试工具与JUnit不兼容,导致错误:
Caused by: java.lang.SecurityException: Prohibited package name: java.io
您有两种选择:
如果您正在测试的单元没有调用GWT.create()
(隐式或显式)或以其他方式依赖本机Javascript,您可以像使用任何其他项目一样使用JUnit(即从命令行) :java java org.junit.runner.JUnitCore ...
Here is some more info on JUnit testing in GWT。
如果您正在测试的单元以某种方式依赖于原生Javascript,则需要使用GWTTestCase
described in the GWT documentation。
考虑查看MVP Pattern,因为其明确的目标之一是使用JUnit尽可能多地测试应用程序(主要是因为它比基于{的测试更快 {1}})。