Getting java.io.IOException when running JUnit test case in Eclipse

喜夏-厌秋 提交于 2019-12-11 10:48:01

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!