在 Eclipse 中运行 JUnit 测试用例时出现 java.io.IOException
这是我的代码
public class JWebUnitTest extends WebTestCase {
public JWebUnitTest(String name) {
super(name);
}
public void setUp() {
getTestContext().setBaseUrl("http://www.google.com");
}
public void testSearch() {
beginAt("/");
setFormElement("q", "httpunit");
submit("btnG");
clickLinkWithText("HttpUnit");
assertTitleEquals("HttpUnit");
assertLinkPresentWithText("User's Manual");
}
}
在失败跟踪中,我看到以下错误:
java.lang.RuntimeException:java.io.IOException (向下移动..) 引起原因:java.net.SocketException:操作超时:连接:可能是由于无效地址所致
为什么“http://www.google.com/”是无效地址? 为什么我会收到此 IOException?
Here's my code
public class JWebUnitTest extends WebTestCase {
public JWebUnitTest(String name) {
super(name);
}
public void setUp() {
getTestContext().setBaseUrl("http://www.google.com");
}
public void testSearch() {
beginAt("/");
setFormElement("q", "httpunit");
submit("btnG");
clickLinkWithText("HttpUnit");
assertTitleEquals("HttpUnit");
assertLinkPresentWithText("User's Manual");
}
}
In the Failure Trace, I see the following error:
java.lang.RuntimeException: java.io.IOException
(moving down..)
Caused by: java.net.SocketException: Operation timed out: connect: could be due to invalid address
Why is "http://www.google.com/" an invalid address?
Why am I getting this IOException?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
既然您将其归类为“在 Eclipse 中”,那么这是否只发生在 Eclipse 中?您可以尝试在 Eclipse 之外运行相同的程序吗?
假设您通过同一台计算机上的网络浏览器具有到 http://www.google.com 的网络连接,则可能是代理问题。要么您需要代理,而 JVM 未配置为使用代理,要么您不需要代理,而 JVM 已配置为使用代理。 (您是否在公司或其他组织网络上运行此程序?)请参阅 http://docs.oracle.com/javase/6/docs/technotes/guides/net/proxies.html 了解如何执行此操作的详细信息。
Since you classified this as "in Eclipse", is this only happening within Eclipse? Can you try running the same outside of Eclipse?
Assuming you have network connectivity to http://www.google.com with a web browser on the same machine, it is likely a proxy issue. Either you need a proxy, and the JVM isn't configured to use one - or you don't need a proxy, and the JVM is being configured to use one. (Are you running this on a corporate or other organizational network?) See http://docs.oracle.com/javase/6/docs/technotes/guides/net/proxies.html for details on how to do this.
我建议您尝试以下任何选项
1.) 清理项目一次。项目 - 清理(在 Eclipse 中)并重建
2.) 尝试将 Eclipse 更新到最新版本
3.) 尝试访问本地主机服务器(这将显示您的代码或 Eclipse 是否确实存在问题)
4.) 您应该是需要代理。所以进行相应配置
I would suggest you to try any of these options
1.) Clean the project once . Project - Clean (in Eclipse) and rebuild
2.) Try updating your eclipse to latest version
3.) Try to hit your localhost server (This will show whether theres really a problem with ur code or with eclipse)
4.) You should be needing a proxy. So configure accordingly