4

鉴于这个非常简单的 Wicket 组件:

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 对其进行单元测试?我需要一个页面吗?

4

2 回答 2

6

在 Wicket 1.5 中有 #startComponentInPage(Component) 将为您创建一个页面,以便您可以测试任何类型的组件。

于 2011-07-11T18:25:09.743 回答
3

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

像这样的东西:

Product product = new Product(/* initialize product here */);
ProductImage pi = new ProductImage("image", product);
tester.startComponent(pi);
tester.assertContains(Pattern.quote(product.getImage()));
于 2011-07-11T14:33:57.243 回答