【发布时间】:2014-09-24 07:57:42
【问题描述】:
我有一个方法的 util 类:
public static void setStyleForWidgetLayout(HTMLPanel panel, int rowQuantity) {
为 HTMLPannel 中的每个小部件分配宽度取决于小部件和行的数量。 很简单的开关。
我想测试这个方法,但是当我使用普通的 JUnit 测试用例创建测试时,我在创建 HTMLPanel 时收到错误消息。
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.
接下来我尝试扩展 GWTTestCase 但它需要实现 getModuleName() 但我没有任何特定模块,因为我测试的类只是 util 类
好吧,我想,让我们模拟一下。我使用了mockito,但发生了错误,与之前的代码部分相同。
然后我找到了 GwtTestWithMockito 类并尝试运行它,但我再次收到错误。
com.googlecode.gwt.test.exceptions.GwtTestConfigurationException: No declared module. Did you forget to add your own META-INF/gwt-test-utils.properties file with a 'gwt-module' property in the test classpath?
我添加了@GWTModule 和这个 META-INF/gwt-test-util.properties。并尝试了不同的配置。我尝试了现有的模块名称而不是现有的模块名称,但我仍然收到上面的错误。
提前致谢
【问题讨论】:
标签: java unit-testing gwt testing mockito