gwt - 无法为使用HTMLPanel的类创建单元测试

时间:2014-09-24 07:57:42

标签: java unit-testing gwt testing mockito

我有一个带有一种方法的util类:

 public static void setStyleForWidgetLayout(HTMLPanel panel, int rowQuantity) {

HTMLPannel中的每个Widget分配widgth取决于小部件和行的数量。 这是非常简单的开关。

我想测试这个方法但是当我用普通的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。并尝试了不同的配置。我尝试了现有的模块名称而不是现有的模块名称,但我仍然收到上述错误。

提前致谢

1 个答案:

答案 0 :(得分:0)

我担心你必须使用GWTTestCase。您的模块名称是模块XML文件的名称。

有时您必须将Panel添加到根面板,我通常这样做只是为了安全起见。

相关问题