使用 JUnit 测试 Tapestry 页面和组件
我通常尝试最小化使用 Selenium 进行的测试,并最大化使用普通的旧后端测试(JUnit、mocking)。使用 Tapestry,我发现很难以后一种方式测试页面和组件,因为回调函数会产生“魔力”。
你能解决这个问题吗?或者您只是将 Selenium 用于整个 Web 层(页面、组件)?
I usually try to minimize testing with Selenium and maximize the usage of plain old back-end testing (JUnit, mocking). With Tapestry I am finding it hard to test pages and components in the latter way due to the "magic" that occurs with the callback functions.
Have you been able to solve this? Or are you just using Selenium for the whole web layer (pages, components)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
根据 Tapestry 文档,使用 PageTester 是对页面和组件进行单元测试的适当方法: https://tapestry.apache.org/unit-testing-pages-or-components.html
但这似乎与 HtmlUnit 风格的 Web 测试类似,因为交互是通过类似 Web 浏览器的界面进行的,而不是通过页面或组件的接口。
编辑
我刚刚尝试了一个简单的页面单元测试,它运行得很好:
AbstractServiceTest 提供了一个测试运行器,它为单元测试类提供 Tapestry 依赖注入。通过 Autobuild,您可以满足 FooPage 的 @Inject 依赖关系,对于组件注入和 @Property 注释元素,您将需要找出其他东西。
According to the Tapestry documentation using PageTester is the appropriate way to do unit testing of Pages and Components: https://tapestry.apache.org/unit-testing-pages-or-components.html
But this seems similar to HtmlUnit style web testing as the interaction happens through a web browser like interface and not through the interface of the Page or Component.
Edit
I just tried a simple unit test for pages and it works quite well :
AbstractServiceTest provides a test runner which provides the Tapestry dependency injection to the unit test class. With Autobuild you get the @Inject dependencies of the FooPage satisfied and for the component injections and @Property annotated elements you will need to figure out something else.
只是为了具体化 Timo 的建议:
然后您将在测试中正确注入字段。记住你@Inject服务(接口)和你@Autobuild实现(类)
Just to concretise on Timo's suggestion:
You will then have properly injected fields in your tests. Remember you @Inject services (interfaces) and you @Autobuild implementations (classes)