Hi Bertrand,

Some progress there. I tried to create real call
of SlingRequestProcessor#doProcessRequest(...), but it becomes pretty hard
to understand and even at this time I didn't create enough mocks to
launch doProcessRequest
method without exception[1]. So I also wrote it in another way which
becomes easier to understand[2]. Here I just mock objects on a first level
and then check that they were called with correct parameters and I also
check that these parameters have correct values. What do you think about
that?

[1]
https://github.com/PetrShypila/sling-builder/blob/engine-module/bundles/engine/src/test/java/org/apache/sling/engine/impl/SlingMainServletTest.java

[2]
https://github.com/PetrShypila/sling-builder/blob/engine-module-simple/bundles/engine/src/test/java/org/apache/sling/engine/impl/SlingMainServletTest.java

-Petr

2015-06-29 14:34 GMT+02:00 Petr Shypila <[email protected]>:

> Yes, thank you. I'll do it in this way.
>
> Best Regards,
> Petr Shypila
>
> > On 29 Jun 2015, at 14:23, Bertrand Delacretaz <[email protected]>
> wrote:
> >
> > Hi Petr,
> >
> >> On Mon, Jun 29, 2015 at 10:40 AM, Petr Shypila <[email protected]>
> wrote:
> >> ...could you please take a look on my
> >> first test for SlingMainServlet[1]...
> >
> > I think it's a good start, but I don't think it's sufficient to just
> > verify that the SlingRequestProcessor is called - you should verify
> > that it is called with the appropriate values, and that its actions
> > are taken into account. Best might be to mock the
> > SlingRequestProcessor (or maybe it's easier to instantiate a
> > SlingRequestProcessorImpl with a few mocks) and test both classes in
> > combination, which is how they are used in practice.
> >
> > This diverges a bit from pure unit tests which should arguably test a
> > single class, but we don't really care here IMO. Testing in a more
> > realistic situation (so SlingMainServlet combined with
> > SlingRequestProcessorImpl) will probably make your tests look more
> > natural, which is good IMO.
> >
> > Does this work for you?
> > -Bertrand
> >
> >
> >> [1]
> >>
> https://github.com/PetrShypila/sling-builder/blob/d4d04af973876aced8dd042ee9b3880ad4e00449/bundles/engine/src/test/java/org/apache/sling/engine/impl/SlingMainServletTest.java
>

Reply via email to