我目前正在使用 GWT、GWTP 构建一个 Web 应用程序。
我对测试有一些疑问:
- 是否有用于 GWTP 或 GWT 的类似 Lint 的工具?
- 如何测试主持人?(带有 Mockito 的 GWTP)
- 如何测试视图?
谢谢。
我目前正在使用 GWT、GWTP 构建一个 Web 应用程序。
我对测试有一些疑问:
谢谢。
演示者可以使用Jukito轻松进行单元测试。这是一个使用 Jukito 测试演示者的快速示例。
@RunWith(JukitoRunner.class)
public class ShowCommentsPresenterTest {
@Inject
private ShowCommentsPresenter showCommentsPresenter;
@Inject
private PlaceManager placeManager;
@Test
public void onReset_PlaceRequestHasNoShowId_ShouldHideView() {
//given
when(placeManager.getCurrentPlaceRequest()).thenReturn(new PlaceRequest());
//when
showCommentsPresenter.onReset();
//then
verify(showCommentsPresenter.getView()).hide();
}
@Test
public void onReset_PlaceRequestHasAShowId_ShouldDisplayView() {
//given
String someShowId = "12345";
when(placeManager.getCurrentPlaceRequest()).thenReturn(new PlaceRequest()
.with(ParameterTokens.getShowId(), someShowId));
//when
showCommentsPresenter.onReset();
//then
verify(showCommentsPresenter.getView()).display();
}
}
在 GWTP 的理念中,视图不应该直接进行单元测试。使用作为 Presenter 从属的哑视图,可以通过对 Presenter 进行单元测试来测试大部分逻辑。像 Selenium 这样的工具更适合测试 UI 交互性。
谷歌发表了一篇关于在 GWT 中使用不同测试方法的精彩文章。一定要检查一下。就个人而言,我在测试诸如业务逻辑之类的后端内容时使用JUnit ,从浏览器的角度测试整个 UI 和应用程序时使用Selenium 。