GwtMockito是GWT应用测试工具。
使用GWTTestCase测试GWT应用会比纯Java测试慢,而且不能使用基于反射的工具,比如模拟测试框架。如果尝试使用常规测试示例,那么会遇到这个错误:
ERROR: GWT.create() is oly usable i cliet code! It caot be called,for example, from server code. If you are ruig a uit test, check that your test case exteds GWTTestCase ad that GWT.create() is ot calledfrom withi a iitializer or costructor.GwtMockito就很好的解决了这个问题,允许从JUit测试中调用GWT.create。返回Mockitomocks。
使用:
public class MyWidget exteds Composite { iterface MyUiBider exteds UiBider<Widget, MyWidget> {} private fial MyUiBider uiBider = GWT.create(MyUiBider.class); @UiField Label umberLabel; private fial NumberFormatter formatter; public MyWidget(NumberFormatter formatter) { this.formatter = formatter; iitWidget(uiBider.createAdBidUi(this); } void setNumber(it umber) { umberLabel.setText(formatter.format(umber)); }}
评论