hadoop-common-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Eric Yang (JIRA)" <j...@apache.org>
Subject [jira] [Updated] (HADOOP-9122) Add powermock library for writing better unit tests
Date Mon, 02 Oct 2017 21:17:00 GMT

     [ https://issues.apache.org/jira/browse/HADOOP-9122?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

Eric Yang updated HADOOP-9122:
------------------------------
    Resolution: Won't Fix
      Assignee:     (was: Eric Yang)
        Status: Resolved  (was: Patch Available)

Mock provides tool chains to run simulation for a piece of code.  It helps to prevent null
pointer exception, and reduce unexpected runtime exceptions.  When a piece of code is finished
with a well-defined unit test, it provides great insights to see author’s intention and
reasoning to write the code.  However, everyone looks at code from a different perspective,
and it is often easier to rewrite the code than modifying and update the tests.   The short
coming of writing new code, there is always danger of losing existing purpose, workaround
buried deep in the code.  On the other hand, if a test program is filling with several pages
of initialization code, and override.  It is hard to get context of the test case, and easy
to lose the original meaning of the test case.  Hence, there are drawback for using mock or
full integration test.

I was in favor of using Powermock in favor of giving user the ability to unit test a class
and reduce external interference initially.  However, I quickly come to realization that Hadoop
usage of protocol buffer serialization technique and java reflection serialization technique
have some difference which prevents powermock to work for certain Hadoop classes.

Hadoop unit tests are written to be bigger than one class, and frequently, a mini-cluster
is spawned to test 5-10 lines of code.  Any simple API test will trigger large portion of
Hadoop code to be initialized.  Hadoop code base will require too much effort to work with
Powermock.  Programs outside of Hadoop can use powermock annotation to prevent mocking Hadoop
classes, such as: @powermockignore({"javax.management_", "javax.xml.", "org.w3c.", "org.apache.hadoop._",
"com.sun.*"}) .  However, working in Hadoop code base, this technique is not practical because
every class in Hadoop prefix with org.apache.hadoop.  It will be heavy upkeep to maintain
the list of prefix packages that can not work with powermock reflection.
Hence, I rest my case for re-opening this issue.

> Add powermock library for writing better unit tests
> ---------------------------------------------------
>
>                 Key: HADOOP-9122
>                 URL: https://issues.apache.org/jira/browse/HADOOP-9122
>             Project: Hadoop Common
>          Issue Type: Improvement
>            Reporter: Radim Kolar
>            Priority: Critical
>         Attachments: HADOOP-9122.001.patch, powermock.txt
>
>
> This library is extension of mockito and easymock libraries. It allows testing of private
methods, private variables and other otherwise untestable stuff.
> http://code.google.com/p/powermock/



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

---------------------------------------------------------------------
To unsubscribe, e-mail: common-issues-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-issues-help@hadoop.apache.org


Mime
View raw message