GwtMockito是GWT应用测试工具。
使用GWTTestCase测试GWT应用会比纯Java测试慢,而且不能使用基于反射的工具,比如模拟测试框架。如果尝试使用常规测试示例,那么会遇到这个错误:
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 calledfrom within an initializer or constructor.GwtMockito就很好的解决了这个问题,允许从JUnit测试中调用GWT.create。返回Mockitomocks。
使用:
public class MyWidget extends Composite { interface MyUiBinder extends UiBinder<Widget, MyWidget> {} private final MyUiBinder uiBinder = GWT.create(MyUiBinder.class); @UiField Label numberLabel; private final NumberFormatter formatter; public MyWidget(NumberFormatter formatter) { this.formatter = formatter; initWidget(uiBinder.createAndBindUi(this); } void setNumber(int number) { numberLabel.setText(formatter.format(number)); }}
评论