是否可以模拟 Java 协议缓冲区消息?

发布于 2024-08-19 08:44:05 字数 297 浏览 1 评论 0 原文

Protocol buffer 类被标记为 final,大概是为了提高效率;然而,这使得它们很难测试—— Mockito 无法模拟/监视最终类。我尝试使用 PowerMockito 但没有成功:在准备用于测试的 final 类时,我收到 ClassFormatError

到目前为止,我的解决方案是创建可模拟的适配器接口,但我希望有一种不那么费力的方法。

Protocol buffer classes are marked final, presumably for efficiency; however, this makes them quite difficult to test with -- Mockito can't mock/spy on final classes. I've tried using PowerMockito with no success: I get a ClassFormatError when preparing the final class for the test.

My solution up until now is to create mockable adapter interfaces, but I'm hoping there's a less laborious approach.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

两相知 2024-08-26 08:44:05

JMockit 可以处理 finalstatic。只需注意如何设置它,因为它需要 -javaagent JVM 参数,或类路径调整,或额外的注释才能模拟 finalstatic 内容。

JMockit can handle final and static. Just pay attention to how to set it up as it requires the -javaagent JVM parameter, or classpath tweaks, or extra annotations to be able to mock final and static stuffs.

黑寡妇 2024-08-26 08:44:05

JDave 有一个与 Unfinalizer .jmock.org/mocking-classes.html" rel="nofollow noreferrer">JMock ClassImposteriser

它无法取消从启动类加载器加载的类,并且在启动测试时需要一个 VM 参数。

JDave has an Unfinalizer that integrates with the JMock ClassImposteriser

It can't unfinalize classes loaded from the the boot classloader, and it requires a VM argument when launching the tests.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文