wicket-core does have some tests too, many are based on MockWebApplication.

Ingram Chen provided an extension to MockWebApplication to help
testing without container. I'm currently working on putting it into
core (see RFE 1287539)

Unfortunately I don't know much about jmock and how it works. Based on
its homepage I can see some of its advantages, but the methods and
classes are final by purpose. Removing final would open up wickets API
at places which are not meant to be replaced. Just providing some
javadoc to users saying "do not replace it" is only a weak solution,
because rather earlier than later users WILL override them and blame
us. Wickets API is meant to be concise, which is very important to
allow for future internal improvements and final is an important
feature to support it.

Juergen

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

Reply via email to