IceFaces 中的 MenuItem 侦听器测试

发布于 2024-08-21 02:52:12 字数 112 浏览 5 评论 0原文

我创建了一个 MenuItem 并使用 allProducts.addActionListener(this); 添加了一个 ActionListener;

有没有办法在单元测试中模拟单击菜单?

I've created a MenuItem and added an ActionListener using allProducts.addActionListener(this);

Is there a way to simulate the menu being clicked in a unit test?

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

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

发布评论

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

评论(1

野生奥特曼 2024-08-28 02:52:12

通常,您应该对 actionHandler 执行的业务方法进行单元测试。
因为在分层应用程序中,处理程序不应该做太多事情,也许只是一些空检查,然后将事件委托给业务方法。因此,您的测试将执行此业务方法,并且不需要“交互”来触发事件。

如果您确实也想测试您的 GUI(处理程序中的代码),您可以尝试 Selenium。它也有一个很好的 eclipse 插件

Normally you should unit test the business method that your actionHandler executes.
Because in a layered application, the handler should not do much, maybe just some nullchecking, and then delegate the event to a business method. So your test will execute this business method, and no "interaction" is needed to fire the event.

If you really want to test your GUI too (the code in the handler), you can try Selenium. It has a nice eclipse plugin too.

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