testInstrumentationRunner "com.example.theapp.utils.CustomAndroidJUnitRunner"
在 Gradle 中设置Run/Debug Configurations -> Android Tests -> MyInstrumentedTest -> General -> Specific instrumentation runner (optional)
并扩展后AndroidJUnitRunner
:
import android.app.Application;
import android.content.Context;
import android.support.test.runner.AndroidJUnitRunner;
public class CustomAndroidJUnitRunner extends AndroidJUnitRunner {
@Override
public Application newApplication(ClassLoader cl, String className, Context context) throws InstantiationException, IllegalAccessException, ClassNotFoundException {
return super.newApplication(cl, className, context);
}
@Override
public void callApplicationOnCreate(Application app) {
super.callApplicationOnCreate(app);
}
}
我设置了 BPnewApplication
并callApplicationOnCreate
看到它callApplicationOnCreate
被调用,但不是newApplication
。可能是什么问题呢?