hbase-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jesse Yates <jesse.k.ya...@gmail.com>
Subject Re: Mocking classes for unit tests Was: asynchbase-1.2.0-rc1 is available for download
Date Wed, 22 Feb 2012 17:29:03 GMT
I put forward rolling in Powermock a while back, but it always seems a bit
overkill for just one or two methods. However, if we make using powermock a
'best practice' going forward, then it becomes reasonable.

Powermock is really nice in that not only can you access private methods
and mock final objects, you can always set private fields and move out
builtin in classes (eg. System, Integer, etc). Pretty sweet.

Only long standing problem I've found with it is that, by necessity, almost
everything is done via reflection, so method names to (power)mock need to
be passed as strings, which can be annoying (but not hard) to maintain.

+1 on adding in powermock as a best practice and updating the book to say

Just my $0.02

Jesse Yates

On Wed, Feb 22, 2012 at 9:23 AM, Ted Yu <yuzhihong@gmail.com> wrote:

> Benoit's comment is directly related to our practice, especially when we
> add new methods which are only called by unit tests.
> ---------- Forwarded message ----------
> From: tsuna <tsunanet@gmail.com>
> Date: Wed, Feb 22, 2012 at 9:13 AM
> Subject: Re: asynchbase-1.2.0-rc1 is available for download
> To: Jim Scott <jim@13ways.com>
> Cc: AsyncHBase <asynchbase@googlegroups.com>
> On Wed, Feb 22, 2012 at 8:50 AM, Jim Scott <jim@13ways.com> wrote:
> > I ask because I am writing some unit tests to make sure that my code is
> > working properly and I cannot mock the HBaseClient because it is final. I
> > completely understand the rationale to make it final, but without it
> > implement an interface or being non-final I cannot mock the object.
> Hi Jim,
> OpenTSDB has unit tests that are mocking out HBaseClient just fine
> [1].  You can mock out pretty much anything on the JVM: final,
> private, JDK stuff, etc.  All you need is the right tools.  I've been
> very happy with PowerMock.  It supports Mockito and EasyMock.
> I've never been keen on mutilating public interfaces for the sake of
> testing.  With tools like PowerMock, we can keep the public APIs tidy
> while mocking and overriding anything, even in the most private guts
> of the classes.
>  [1]
> https://github.com/stumbleupon/opentsdb/blob/master/src/uid/TestUniqueId.java#L66
> --
> Benoit "tsuna" Sigoure
> Software Engineer @ www.StumbleUpon.com

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message