Last active
August 29, 2015 14:08
-
-
Save blundell/ff2ac1d5ff0a41519c36 to your computer and use it in GitHub Desktop.
assertActivityRequiresPermission() Why doesn't this test pass?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | |
package="com.blundell.myapplication"> | |
<application> | |
<activity | |
android:name=".SecondActivity" | |
android:permission="perm.foo.bar" /> | |
</application> | |
</manifest> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.blundell.myapplication; | |
import android.app.Application; | |
import android.test.ApplicationTestCase; | |
/** | |
* <a href="http://d.android.com/tools/testing/testing_android.html">Testing Fundamentals</a> | |
*/ | |
public class ApplicationTest extends ApplicationTestCase<Application> { | |
private static final String PACKAGE = "com.blundell.myapplication"; | |
public ApplicationTest() { | |
super(Application.class); | |
} | |
public void testSecondActivityRequiresFooBarPermission() throws Exception { | |
assertActivityRequiresPermission(PACKAGE, PACKAGE + ".SecondActivity", "perm.foo.bar"); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
junit.framework.AssertionFailedError: expected security exception for perm.foo.bar | |
at android.test.AndroidTestCase.assertActivityRequiresPermission(AndroidTestCase.java:99) | |
at com.blundell.myapplication.ApplicationTest.testSecondActivityRequiresFooBarPermission(ApplicationTest.java:15) | |
at java.lang.reflect.Method.invokeNative(Native Method) | |
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:191) | |
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:176) | |
at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:554) | |
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1701) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.blundell.myapplication; | |
import android.app.Activity; | |
public class SecondActivity extends Activity { | |
} |
I also changed the testApplicationId = "com.foo"
as a sanity check with no change
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hmm it does run under another application (android instrumentation) so it's install package is
com.blundell.myapplication.test
but I changed the java package anyway to give it a try and that didn't work