Ahm*_*our 16 java eclipse proxy junit system-properties
如果您将系统代理设置为HTTP,则HTTP
仅当从main
java应用程序的方法运行时,才会打印以下内容.
但是,如果从JUnit 4测试(在eclipse中)调用它,它总是打印DIRECT
.
还注意到-Djava.net.useSystemProxies=true
在eclipse 中定义:运行配置 - >参数 - > VM参数.测试只是挂起.
知道发生了什么事吗?
非常感谢,
public void printSystemProxy() {
System.setProperty("java.net.useSystemProxies", "true");
try {
final List<Proxy> list = ProxySelector.getDefault().select(new URI("http://foo/bar"));
for (final Proxy proxy : list) {
System.out.println(proxy.type());
}
}
catch (final URISyntaxException e) {
throw new IllegalStateException(e);
}
}
Run Code Online (Sandbox Code Playgroud)
小智 6
尝试使用以下VM参数进行TestRunner配置(右键单击/ RunAs ...):
-Dhttp.proxyHost=<YOUR_PROXY>
-Dhttp.proxyPort=<YOUR_PORT>
-Dhttp.nonProxyHosts=<IF YOU NEED THIS (pipe as separator)>
-Dhttp.proxyUser=<YOUR_NAME>
-Dhttp.proxyPassword=<YOUR_PASWORD>
Run Code Online (Sandbox Code Playgroud)