You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@geode.apache.org by Jens Deppe <jd...@pivotal.io> on 2015/12/17 19:14:24 UTC

Using PowerMock

Hey All,

I've just had a need to mock some static methods. Mockito doesn't
allow mocking statics, but PowerMock does.

Kirk suggested to put this up for discussion before going ahead to use
PowerMock. Does anyone have any (bad) experience with PowerMock or
other reservations about using it.

More generally, we should obviously be trying to factor out as much
static code as possible, but sometimes that's not reasonable to do (at
least in the short term).

Thoughts? Comments?

Thanks
--Jens

Re: Using PowerMock

Posted by Sai Boorlagadda <sb...@pivotal.io>.
If its possible to encapsulate static method invocations into an instance
method then we can use a *spy* to mock the new instance methods on a real
object, that way you could get around mocking statics.

But if a class is using lot of different static methods, then creating
instance method for each static method may not be feasible.

So +1

Sai

On Thu, Dec 17, 2015 at 10:36 AM, Jovaughn Lockridge <jo...@gmail.com>
wrote:

> Why should you factor out static code?  Is it because it is hard to test?
>
> Sent from my iPhone
>
> > On Dec 17, 2015, at 1:14 PM, Jens Deppe <jd...@pivotal.io> wrote:
> >
> > Hey All,
> >
> > I've just had a need to mock some static methods. Mockito doesn't
> > allow mocking statics, but PowerMock does.
> >
> > Kirk suggested to put this up for discussion before going ahead to use
> > PowerMock. Does anyone have any (bad) experience with PowerMock or
> > other reservations about using it.
> >
> > More generally, we should obviously be trying to factor out as much
> > static code as possible, but sometimes that's not reasonable to do (at
> > least in the short term).
> >
> > Thoughts? Comments?
> >
> > Thanks
> > --Jens
>



-- 
Sai Boorlagadda

Re: Using PowerMock

Posted by Jovaughn Lockridge <jo...@gmail.com>.
Why should you factor out static code?  Is it because it is hard to test?

Sent from my iPhone

> On Dec 17, 2015, at 1:14 PM, Jens Deppe <jd...@pivotal.io> wrote:
> 
> Hey All,
> 
> I've just had a need to mock some static methods. Mockito doesn't
> allow mocking statics, but PowerMock does.
> 
> Kirk suggested to put this up for discussion before going ahead to use
> PowerMock. Does anyone have any (bad) experience with PowerMock or
> other reservations about using it.
> 
> More generally, we should obviously be trying to factor out as much
> static code as possible, but sometimes that's not reasonable to do (at
> least in the short term).
> 
> Thoughts? Comments?
> 
> Thanks
> --Jens

Re: Using PowerMock

Posted by pulkit chandra <pu...@gmail.com>.
+1

Specially until Geode is at that state. I have created few Unit Test cases
with PowerMock and it works well, specially with Geode use cases.

Best Regards,
*Pulkit Chandra*


On Thu, Dec 17, 2015 at 1:14 PM, Jens Deppe <jd...@pivotal.io> wrote:

> Hey All,
>
> I've just had a need to mock some static methods. Mockito doesn't
> allow mocking statics, but PowerMock does.
>
> Kirk suggested to put this up for discussion before going ahead to use
> PowerMock. Does anyone have any (bad) experience with PowerMock or
> other reservations about using it.
>
> More generally, we should obviously be trying to factor out as much
> static code as possible, but sometimes that's not reasonable to do (at
> least in the short term).
>
> Thoughts? Comments?
>
> Thanks
> --Jens
>