Created
July 11, 2011 08:38
Invoking android.test.AndroidTestCase#getTestContext method
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.lang.reflect.InvocationTargetException; | |
import java.lang.reflect.Method; | |
import android.content.Context; | |
import android.test.AndroidTestCase; | |
public class AndroidExtendedTestCase extends AndroidTestCase { | |
public Context getTestContext(){ | |
Context context = null; | |
@SuppressWarnings("unchecked") | |
Class<AndroidExtendedTestCase> clz = (Class<AndroidExtendedTestCase>) this.getClass(); | |
try { | |
Method method = clz.getMethod("getTestContext"); | |
context = (Context) method.invoke(this); | |
} catch (SecurityException e) { | |
fail(); | |
} catch (NoSuchMethodException e) { | |
fail(); | |
} catch (IllegalArgumentException e) { | |
fail(); | |
} catch (IllegalAccessException e) { | |
fail(); | |
} catch (InvocationTargetException e) { | |
fail(); | |
} | |
return context; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment