问题
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?
回答1:
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
回答2:
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.
来源:https://stackoverflow.com/questions/8981949/getting-java-io-ioexception-when-running-junit-test-case-in-eclipse