title: Unable to test code requiring CHANGE_NETWORK_STATE / WRITE_SETTINGS permission on Marshmallow
body: <p>I am trying to upgrade my app's targetSDK to above 23 and I've run into a small problem. I have an activity that binds traffic to Wifi (to measure the network speed to the router, even if the router is not connected to the internet). In order for that to happen my app needs the <code>CHANGE_NETWORK_STATE</code> permission. That permission is usually granted directly if declared in the manifest. On Android 6.0 (exact, this was fixed in 6.0.1 IIRC) <code>CHANGE_NETWORK_STATE</code> is broken and won't be granted so you need the <code>WRITE_SETTINGS</code> permission instead. I've implemented a way for Android 6.0 Users to grant that permission but when I want to test my Activity using espresso I am unable to do so. Permissions are granted to tests by adding something like</p>
  
  <p><code>@Rule
      public GrantPermissionRule runtimePermissionRule = GrantPermissionRule.grant(Manifest.permission.CHANGE_NETWORK_STATE);</code></p>
  
  <p>to the TestCase. That worked in other places in the app but for this I get
  <code>junit.framework.AssertionFailedError: Failed to grant permissions, see logcat for details</code> in my test results. In logcat I find <code>E/GrantPermissionCallable: Permission: android.permission.WRITE_SETTINGS cannot be granted!</code> or the same with <code>CHANGE_NETWORK_STATE</code>, I've tried granting both and they both don't work. Is there any other way for me to grant the permission in the testing environment? Or am I unable to test this activity on 6.0 devices from now on?</p>