android - Is there a way to unit-test code in abstract class protected method of AsyncTask? -
long story short, need test code executed in "doinbackground" method of asynctask.
this in android studio powermockito / mockito / robolectric / junit4.
i aware testing written code far ideal,
have no word in , can't change original code.
this case :
public void methodtotest(){ new asynctask<integer, void, boolean>() { @override protected boolean doinbackground(integer... integers) { //how test code written on here ? return false; } } }
is there way solve ? suggestions appreciated
there ugly working detour here: reflection.
the point is: above code declares anonymous inner class. thing is: anonymous inner classes have unique, defined name.
and using reflection, possible instantiate objects of such anonymous inner classes.
you can have here idea how work.
boiling down to: when able instantiate object of class contains methodtotest()
; able instantiate objects of inner class. , should able call methods on either of these objects.
but when works , gets reasonable unit tests: want show people writing production code tests. make clear them kind of harm unwillingness write testable production code causing!
Comments
Post a Comment