I'm sorry you had a hard time making testing work. It is certainly an
area that needs improvement then. We need imput like you gave for
that, and of course any help like code contributions/ patches are
appreciated too. Btw, Martijn is interested in improving this area of
Wicket. He's also an active comitter on jWebUnit, and he's known as
the test zealot at Topicus ;). An explicit RFE for better support unit
testing would be good idea. Certainly when you can describe what you
would like to test how.
Eelco
On 10/4/05, Eduardo Rocha <[EMAIL PROTECTED]> wrote:
> I would like to to post about how difficult is being unit test some of my
> code with Wicket and get some feedback about it.
>
> First of all, I don't think the wicket-examples does a very good job on how
> to unit test wicket code, since having a embedded Jetty instance means
> integration tests. The only code in wicket-examples that does help with unit
> tests is inside the displaytag example (SortableTableHeadersTest), which
> uses MockWebApplication.
>
> Of course the fact that dependency injection is not supported on pages
> provides little help, but I don't think this is the worst thing. I have a
> very simples class, that is supposed to interact with a Component. I can't
> mock this interaction, not even using cglib with jmock, because most methods
> are final. I am testing the following method:
>
> public void doAction() {
> MyObject object = (MyObject) _component.getModelObject();
> _service.save(piloto);
> _component.info("This was saved: " + object.getName());
> }
>
> The test is something like:
>
> public void testDoAction() {
>
> _mockComponent.stubs().method("getModel").will(returnValue(new
> Model((Serializable) _myObject)));
>
> _mockService.expects(once()).method("save").with(eq(_myObject));
>
> _mockComponent.expects(once()).method("info").with(contains(_name));
> _context.doAction();
> }
>
> The notes on the code above are:
>
> I had to "stub" getModel, because the method I actually expect to be called
> (getModelObject) is final, and it uses getModel, that it isn't. But
> Component.info is final as well, and calls getPage (also final), which calls
> findPage (final), which calls findParent (final), so it's impossible to set
> any expectations neither stub any method. The tests always fails, because
> the Component does not find its page.
>
> I would like to know if other are facing the same problems, or whether I am
> doing the wrong kind of development with Wicket, and whether I am better to
> go another way.
>
-------------------------------------------------------
This SF.Net email is sponsored by:
Power Architecture Resource Center: Free content, downloads, discussions,
and more. http://solutions.newsforge.com/ibmarch.tmpl
_______________________________________________
Wicket-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/wicket-user