How to unit test a custom Wicket component

浪子不回头ぞ 提交于 2019-12-10 16:28:58

问题


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())));
    }
}

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


回答1:


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()));



回答2:


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



来源:https://stackoverflow.com/questions/6651539/how-to-unit-test-a-custom-wicket-component

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!