Skip to content

Instantly share code, notes, and snippets.

@naosim
Created September 5, 2012 16:04
Show Gist options
  • Save naosim/3639063 to your computer and use it in GitHub Desktop.
Save naosim/3639063 to your computer and use it in GitHub Desktop.
AndroidTestCaseからテストプロジェクトのContextを取得する方法
public class HogeTest extends AndroidTestCase {
/**
* AndroidTestCaseからテストプロジェクトのContextを取得する
* @return
*/
public Context getTestProjectContext() {
try {
// リフレクションで取得
Method method = getClass().getMethod("getTestContext");
return (Context) method.invoke(this);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment