[Cs5500] Testing issues in BinaryGame.java

Rick Keilty rkeilty at ccs.neu.edu
Tue Apr 19 22:40:00 EDT 2011


Another interesting and common hurdle in unit testing is the subject of
private methods.  Many argue that if a method is private is by definition
shouldn't be unit testable because the higher level test cases should catch
issues with it, or it should be wrapped in its own package.  But sometimes
it can literally become unavoidable to do anything except unit test private
methods (especially when dealing with a huge codebase that can't be easily
refactored).

An interesting approach to this problem in java is to use Reflection and the
API that java exposes to temporarily change the security permissions on an
object method to allow it to be publicly invoked.  An example of this can be
read at http://www.artima.com/suiterunner/private3.html (see the section
that starts dealing with Method method = targetClass.getDeclaredMethod)
The nice thing about this is that it keeps a nice clear distinction between
your unit tests and code paths, and retains the same private security
permissions on the object while allowing outside code to access it.

This type of unit testing should not be used as a substitute for good object
orientated code and test driven developement, but rather as a complement to
ensure adequate test coverage over complex code bases.

-Rick

On Sun, Apr 17, 2011 at 10:39 AM, Reto Kleeb <kleeb.r at husky.neu.edu> wrote:

> I highly recommend the following blog entry:
>
>
> http://googletesting.blogspot.com/2008/08/by-miko-hevery-so-you-decided-to.html
>
> They use a familiar term in #2...
>
> Best,
>
> Reto
>
> On 4/17/11 7:06 AM, Karl Lieberherr wrote:
> > Hi Parvathy:
> >
> > it is very worthwhile asking for making the code easier to test. Kent
> > Beck was propagating already in the 80's the view that one method
> > should do one thing. Which makes methods easier to test.
> >
> > In our retrospective on the 25th I would like you to give a short
> > presentation on PRX's needs for testability and how the needs were met
> > by the developers.
> >
> > -- Karl
> >
> > On Fri, Apr 15, 2011 at 6:43 PM, Parvathy Nair<parvathyunair at gmail.com>
>  wrote:
> >>
> >> Hi,
> >> We found issues to test the code in BinaryGame.java since the validation
> is
> >> in a single unit and it is not easy to test starting from line 148.  It
> >> would be lot easier to test if these were written in public methods
> which we
> >> can call and test.
> >> Thank You!
> >> Parvathy (PRX team)
> >>
> >>
> >> _______________________________________________
> >> Cs5500 mailing list
> >> Cs5500 at lists.ccs.neu.edu
> >> https://lists.ccs.neu.edu/bin/listinfo/cs5500
> >>
> >>
> >
> > _______________________________________________
> > Cs5500 mailing list
> > Cs5500 at lists.ccs.neu.edu
> > https://lists.ccs.neu.edu/bin/listinfo/cs5500
>
> _______________________________________________
> Cs5500 mailing list
> Cs5500 at lists.ccs.neu.edu
> https://lists.ccs.neu.edu/bin/listinfo/cs5500
>
-------------- next part --------------
HTML attachment scrubbed and removed


More information about the Cs5500 mailing list