For regular gradle actions, I have a gradle.properties file in my project or home which configures the proxy details (host/port etc.)
When using GradleRunner, the gradle.properties file is ignored by intention:
"Any configuration in the default Gradle user home directory (e.g. ~/.gradle/gradle.properties) is not used for test execution. The TestKit does not expose a mechanism for fine grained control of all aspects of the environment (e.g., JDK). Future versions of the TestKit will provide improved configuration options."
(from https://docs.gradle.org/current/userguide/test_kit.html#sec:controlling_the_build_environment)
Question:
How can I configure a proxy when using GradleRunner?
You can simply add a
gradle.propertiesfile with the proxy settings to your test project (run withGradleRunner). Here’s a complete example project (Gradle 7.1 Wrapper files not shown):build.gradlesrc/test/groovy/com/example/MyTest.groovyI’ve used a non-existing dummy proxy which leads to a test failure because of a test/connection timeout (→
SpockTimeoutError). Using a real proxy instead, the test should succeed.