gpt4 book ai didi

unit-testing - GWT JUnit 测试

转载 作者:行者123 更新时间:2023-12-04 04:15:22 29 4
gpt4 key购买 nike

我正在尝试对 GWT 进行非常 JUnit 测试,但它失败了

public class CheckTest extends TestCase
{

private ServiceAsync RPC;
private HandlerManager EventBus;
private CreateTopicPresenter.Display CTV;
private CreateTopicPresenter CTP;

protected void setUp()
{
RPC= createStrictMock(ServiceAsync.class);
EventBus = new HandlerManager(null);
CTV= createStrictMock(CreateTopicView.class);
CTP= new CreateTopicPresenter(CTV,RPC,EventBus);
}
public void testCheck()
{

CTP.View.getFirstMessage().setValue("MessageTest");
assertTrue(CTP.View.getFirstMessage().getValue().equals("MessageTest"));
}

堆栈跟踪:
 java.lang.ExceptionInInitializerError
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 net.sf.cglib.proxy.Enhancer.setCallbacksHelper(Enhancer.java:619)
at net.sf.cglib.proxy.Enhancer.setThreadCallbacks(Enhancer.java:612)
at net.sf.cglib.proxy.Enhancer.registerCallbacks(Enhancer.java:581)
at org.easymock.internal.ClassProxyFactory.createProxy(ClassProxyFactory.java:194)
at org.easymock.internal.MocksControl.createMock(MocksControl.java:60)
at org.easymock.EasyMock.createStrictMock(EasyMock.java:70)
at com.BiddingSystem.client.CheckTest.setUp(CheckTest.java:26)
at junit.framework.TestCase.runBare(TestCase.java:128)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:120)
at junit.framework.TestSuite.runTest(TestSuite.java:230)
at junit.framework.TestSuite.run(TestSuite.java:225)
at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:130)
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.UnsupportedOperationException: ERROR: GWT.create() is only usable in client code! It cannot be called, for example, from server code. If you are running a unit test, check that your test case extends GWTTestCase and that GWT.create() is not called from within an initializer or constructor.
at com.google.gwt.core.client.GWT.create(GWT.java:91)
at com.google.gwt.user.client.ui.UIObject.<clinit>(UIObject.java:188)
... 24 more

最佳答案

您需要扩展 GWTTestCase 基类型以测试依赖于 GWT 运行时的代码(例如调用 GWT.create() 或 JSNI 方法)。请注意,GWTTestCase 也必须与 GWT 兼容,因此这将限制您对测试库的选择。

理想情况下,您的大部分应用程序代码都可以使用“纯”TestCases 进行测试,而 GWTTestCases 只测试特定于客户端的代码,因为后者具有更高的开销。

http://www.gwtproject.org/articles/testing_methodologies_using_gwt.html

关于unit-testing - GWT JUnit 测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5138221/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com