Robolectric can download Android runtime artifacts while tests are running. A build tool successfully resolving the project’s ordinary dependencies does not establish that this test-time download uses the same proxy.

Robolectric 4.9.1 and later document these system properties for that downloader:

robolectric.dependency.proxy.host=proxy.example
robolectric.dependency.proxy.port=8080

Pass them to the JVM running the tests. For public artifact downloads allowed through an unauthenticated HTTP intermediary, use an address from the HTTP proxy list in these host and port properties. For an Android project using Gradle’s Groovy DSL, the relevant configuration can be:

android {
    testOptions {
        unitTests.all {
            systemProperty 'robolectric.dependency.proxy.host', 'proxy.example'
            systemProperty 'robolectric.dependency.proxy.port', '8080'
        }
    }
}

Keep this with the project’s existing test configuration. A property supplied only to the Gradle launcher is not evidence that a forked test JVM received it.

For a deliberately disconnected test environment, Robolectric also documents robolectric.offline and robolectric.dependency.dir. That arrangement requires the correct runtime artifacts to be staged in the specified directory. Gradle’s own offline cache is not a replacement for the directory expected by Robolectric’s offline resolver.

Mikanda mikatakata