开发者

How to unit test a custom Wicket component

开发者 https://www.devze.com 2023-03-19 23:16 出处:网络
Given this really simple Wicket component: public class ProductImage extends WebComponent { public ProductImage(String id, Product p) {

Given this really simple Wicket component:

public class ProductImage extends WebComponent {

    public ProductImage(String id, Product p) {
        super(id, new Model(p));
        add(n开发者_运维问答ew AttributeModifier("src", true, new Model(p.getImage())));
    }
}

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


In Wicket 1.5 there is #startComponentInPage(Component) which will create a page for you so you can test any kind of component.


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

Something like this:

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

精彩评论

暂无评论...
验证码 换一张
取 消