GWT Mockito 集成
我正在尝试在 GWT 项目中设置并使用 Mockito,但在客户端(在 javascript 中)使用它时遇到问题。我尝试添加一个模块并包含 Mockito,但它似乎不起作用(有很多错误)。我还尝试从 svn 进行完整检查并以这种方式将 GWT 集成到其中,但出现同样的错误。这应该怎么做呢?谢谢。
I'm trying to set up and use Mockito into a GWT project, and I'm having trouble using it on the client side (in javascript). I tried to add a module and include Mockito, but it seems not to work (lots of errors). I also tried to do a full checkout from svn and integrate GWT in it that way, the same errors. How should this be done? Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
显然,使用模拟框架(如 Mockito)测试的 GWT 代码在 JVM 中运行,并且没有编译为 JavaScript。因此,任何与 JavaScript 相关的实现都应该使用模拟对象进行模拟或存根。
MVP(MVC 的变体)是 GWT 中广泛采用并简化测试的一种架构。 MVP 将大部分有意义的功能放在称为演示者的类中。 Presenter 不依赖于 GWT 实现类,而是依赖于 GWT 接口(大部分)。然后应用 Mockito 来模拟/存根这些接口以对演示者类进行单元测试。
此博客已满有关 GWT 中的 MVP 和使用模拟对象 (EasyMock) 进行测试的示例。
GWT code tested with mocking framework (like Mockito) runs in JVM and no compiling to JavaScript, obviously. Thus, any JavaScript-related implementations should be mocked or stubbed using mock objects.
One architecture that receives wide adoption in GWT and that simplifies testing is MVP (variation of MVC). MVP places majority of meaningful functionality inside classes called presenters. Presenters do not rely upon GWT implementation classes but instead depend on GWT interfaces (mostly). Then Mockito is applied to mock/stub those interfaces to unit test presenter classes.
This blog is full of examples on both MVP in GWT and testing with mock objects (EasyMock).
现在有 https://github.com/google/gwtmockito 这可能就是您所需要的。
And now there is https://github.com/google/gwtmockito which is probably what you need.
如果没有更多细节,我只能说模拟框架大量使用动态代理和运行时代码生成,而 GWT 不会编译这些代码。
最好的选择是在普通的 JUnit 测试中使用这些模拟。
Without more specifics I can only say that mocking frameworks make heavy use of dynamic proxies and run-time code generation which will not be compiled by GWT.
Your best bet is using these mocks in plain JUnit tests.