hbase-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ted Yu <yuzhih...@gmail.com>
Subject Mocking classes for unit tests Was: asynchbase-1.2.0-rc1 is available for download
Date Wed, 22 Feb 2012 17:23:41 GMT
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.


Benoit "tsuna" Sigoure
Software Engineer @ www.StumbleUpon.com

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