GwtMockitoGWT 應用測試工具
GwtMockito 是 GWT 應用測試工具。
使用 GWTTestCase 測試 GWT 應用會比純 Java 測試慢,而且不能使用基于反射的工具,比如模擬測試框架。如果嘗試使用常規(guī)測試示例,那么會遇到這個錯誤:
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.
GwtMockito 就很好的解決了這個問題,允許從 JUnit 測試中調用 GWT.create。返回 Mockito mocks。
使用:
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));
}
}
評論
圖片
表情
