如何对自定义Wicket组件进行单元测试 [英] How to unit test a custom Wicket component

查看:82
本文介绍了如何对自定义Wicket组件进行单元测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

给出这个非常简单的Wicket组件:

Given this really simple Wicket component:

public class ProductImage extends WebComponent {

    public ProductImage(String id, Product p) {
        super(id, new Model(p));
        add(new AttributeModifier("src", true, new Model(p.getImage())));
    }
}

如何使用WicketTester对其进行单元测试?我需要页面吗?

How to unit test it using WicketTester? Do I need a page?

推荐答案

我实际上还没有这样做(我只有经过测试的面板),但 startComponent() 似乎是这样做的方法。

I haven't actually done that (I've only tested panels), but startComponent() seems to be the way to do it.

是这样的:

Product product = new Product(/* initialize product here */);
ProductImage pi = new ProductImage("image", product);
tester.startComponent(pi);
tester.assertContains(Pattern.quote(product.getImage()));

这篇关于如何对自定义Wicket组件进行单元测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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