[
https://issues.apache.org/jira/browse/HBASE-5456?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13455151#comment-13455151
]
Jesse Yates commented on HBASE-5456:
------------------------------------
Reviving this discussion after talking at recent pow-wow. In short, powermock
has some _interesting_ features -making it very powerful - that will really
help to cleanup the codebase.
For instance, it can help get rid of are the test visible methods. Yes, on one
hand you could subclass the class you are testing to get at the protected
methods, but then you have the issue of making that class loadable as well. It
can easily spiral out of control where everything is dynamically loadable, just
so you can check the state of one variable. Also, this can lead to inadvertent
race conditions for timing related things, where the test-exposed method could
be really simple.
Also, it helps you get real objects into a state that is more easily testable.
Rather than rejiggering everything through a high-level interface, you can
specify things succinctly and more easily when you can introspect the object.
Another great use is for managing timing issues. A lot of times to test timing
of things we rely on sleeps or adding latches. The former is really brittle and
the latter makes the code incredibly more complicated than it needs to be, just
for testing.
Problems with powermock:
* complicated - yeah, it can be a bit funky, but you get used to it.
* brittle - its doing reflection so there are a lot of string method/object
names used. That's the problem with introspection of objects and the price we
pay for cleaner running code. Tests break when you change stuff though, so you
know if something goes arwy.
Stack raised a possible concern that he couldn't get powermock working on the
current codebase. However, I volunteered to spend the time to figure that out
(at least initially) and don't think it will be all that bad.
Thoughts? If people are +1, I'll work on a simple patch that adds powermock to
the pom and makes a change to a test to use it.
> Introduce PowerMock into our unit tests to reduce unnecessary method exposure
> -----------------------------------------------------------------------------
>
> Key: HBASE-5456
> URL: https://issues.apache.org/jira/browse/HBASE-5456
> Project: HBase
> Issue Type: Task
> Reporter: Ted Yu
>
> We should introduce PowerMock into our unit tests so that we don't have to
> expose methods intended to be used by unit tests.
> Here was Benoit's reply to a user of asynchbase about testability:
> 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
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira