I have business logic in a UI-less snippet that I have to check. I tried 2 options, and both of them failed.
1. Use AndroidTestCase and create mock activity.
Following code
@Override
protected void setUp() {
Intent i = new Intent(getTestContext(), TestActivity.class);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
getTestContext().startActivity(i);
}
throws an exception
Permission denied: checkComponentPermission() reqUid=10104
java.lang.SecurityException: Permission Denial: starting Intent { flg=0x10000000 cmp=com.xxx.iabsample.test/.TestActivity } from ProcessRecord{40769510 28116:com.xxx.iabsample/10070 (pid=28116, uid=10070) requires null
2. Use ActivityInstrumentationTestCase2 with mock activity
the code
public class IabTest extends ActivityInstrumentationTestCase2<TestActivity> {
public IabTest() {
super("com.xxx.iabsample.test", TestActivity.class);
}
}
throws an exception
java.lang.RuntimeException: Unable to resolve activity for: Intent { act=android.intent.action.MAIN flg=0x10000000 cmp=com.xxx.iabsample/.test.TestActivity }
He seems to be trying to get started with the target destination application, not a test application.
So what is the correct way to check for fragments?
source
share