Wicket 测试 startPanel(Panel) 和 PageParameters - 如何设置它们? [英] Wicket testing startPanel(Panel) and PageParameters - how to set them?

查看:29
本文介绍了Wicket 测试 startPanel(Panel) 和 PageParameters - 如何设置它们?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前我正在使用 WicketTester 的 startPanel 方法来测试我的面板.在这些面板中,我经常使用 PageParameters 访问数据,使用 getPage().getPageParameters().但是,startPanel 方法不会为 DummyPage 初始化任何页面参数,也不提供设置页面参数的功能.

Currently I'm using the WicketTester's startPanel method to test my panels. Within these panels I often use PageParameters to access data, using getPage().getPageParameters(). However, the startPanel method does not initialize any page parameters for the DummyPage, nor does it offer me functionality to set page parameters.

如何在面板测试期间设置我的页面参数?

How do I set my page parameters during panel tests?

推荐答案

我个人认为,通过 getPage().getPageParameters() 获取 PageParameters 是次优的要走的路.

Personally, I think, getting the PageParameters via getPage().getPageParameters() is a suboptimal way to go.

正如您所见,它引入了从您的面板到您的页面的依赖关系,这使得它们紧密耦合且难以测试.

It introduces a dependency from your panel to your page which makes them tightly coupled and hard to test, as you can see.

如果您需要从 Panel 中访问 PageParameters,请通过创建接受这些的构造函数来注入它们,类似于

If you need to access the PageParameters from within your Panel, inject them by creating a constructor accepting these, something along the lines of

private PageParameters params;

public MyPanel (String id, Model<T> model, PageParameters params) {
    super(id, model);
    this.params = params;
    ...
}

这样你就可以在你的 Panel 中使用 Parameters,用你的任何 PageParameters 构造 Panel可以想象在你的测试中你避免了被证明是不利的耦合.

This way you can use the Parameters from within your Panel, construct the Panel with any PageParameters you can imagine in your tests and you avoided the coupling that proved to be disadvantageous.

这篇关于Wicket 测试 startPanel(Panel) 和 PageParameters - 如何设置它们?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆