On Sat, Apr 26, 2008 at 1:40 AM, Nino Saturnino Martinez Vazquez Wael
<[EMAIL PROTECTED]> wrote:
>
>
>  James Carman wrote:
>
> > Why are you using the Spring injector to inject your dependencies?
> > Can you not manually inject your dependencies?  Adding stuff manually
> > to a Spring context and then having the Spring injector inject it
> > doesn't really test what's going to be going on "in production"
> > anyway.  If it were me, I'd provide "setters" for my dependencies and
> > just set them that way with my mock objects.
> >
> >
> >
>  It can be pretty use fully for several purposes, one could be using mock
> object's instead (like easymock).

I understand the importance of having the stuff injected.  My question
is whether or not you should be using Spring to inject them during
unit tests.  You don't use Spring to inject stuff during other types
of unit tests, so why should you use it for Wicket Pages/Components?
Why can't you just do this:

public class MyWebPage extends WebPage
{
  @SpringBean
  private MyService myService;

  public void setMyService(MyService myService)
  {
    this.myService = myService;
  }
}

public class TestMyWebPage
{
  @Test
  public void testPageRendersProperly()
  {
    WicketTester tester = new WicketTester();
    MyWebPage page = new MyWebPage();
    MyService myService = ...; // Create mock object here using jmock/easymock!
    page.setMyService(myService);
    tester.startPage(myPage);
    ...
  }
}

Is that not an acceptable way to unit test the pages?  To me, this is
much simpler.  This is how you test normal classes that are used
inside a Spring context.

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to