@blog.justoneplanet.info

日々勉強

AndroidTestCaseでテストアプリ側のContextを取得する

メモ。

public class AndroidExtendedTestCase extends AndroidTestCase {
    public Context getTextContext() throws SecurityException, NoSuchMethodException, IllegalArgumentException, IllegalAccessException, InvocationTargetException {
        Class<? extends AndroidExtendedTestCase> clz = (Class<? extends AndroidExtendedTestCase>) this.getClass();
        Method method = clz.getMethod("getTestContext");
        Context context = (Context) method.invoke(this);
        return context;
    }
}

参考

コメントはまだありません»

No comments yet.

RSS feed for comments on this post.TrackBack URL

Leave a comment