他の apk からアクティビティをテストしたいと思います。アクティビティとインストルメンテーションを取得する必要があるため、このテストは ActivityInstrumentationTestCase2 ( http://developer.android.com/reference/android/test/ActivityInstrumentationTestCase2.html ) を拡張します。
私は次のように DexClassLoader を使用しようとしています:
public MainActivityTest() throws ClassNotFoundException{
super((new DexClassLoader(
"/data/app/my-application.apk", "/data/app/my-application",null, MainActivityTest.class.getClassLoader())).loadClass("my-application.MainActivity")))}
しかし、結果として例外が発生します:optimizedDirectory not readable/writable: /data/data/valentin.myapplication2
それを行うための解決策はありますか?
これを後で使用するため、アクティビティが必要です。activity.getWindow().getDecorView()
ご参考までに:
@Before
public void setUp() throws Exception {
super.setUp();
injectInstrumentation(InstrumentationRegistry.getInstrumentation());
mActivity = getActivity();
}
@Test
public void testRecorder(){
new ActivityListener(InstrumentationRegistry.getInstrumentation(),mActivity,12).start();
while(true){
}
}