1

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?

ziesemer
  • 27,712
  • 8
  • 86
  • 94
dale
  • 439
  • 3
  • 11
  • 28

2 Answers2

1

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.

ziesemer
  • 27,712
  • 8
  • 86
  • 94
  • yes, it's a corporate network, don't know if we have a proxy, but I can definitly see a Auto Config Script being set under LAN settings. I have no issue browsing to google.com on a normal browser – dale Jan 24 '12 at 05:13
  • @user1096804 - You need to apply the same settings to your Java process or code. See the link I just added to the end of my answer for details. – ziesemer Jan 24 '12 at 05:15
  • Thanks ziesemer, i've just found a proxy somewhere and applied to my code, seem to be successful. But when it comes down to submit("btnG"), I got an syntax error SyntaxError: syntax error (httpunit; line 155) at org.mozilla.javascript.NativeGlobal.constructError(NativeGlobal.java:597) at org.mozilla.javascript.TokenStream.reportSyntaxError(TokenStream.java:1324)... – dale Jan 24 '12 at 05:38
  • @user1096804 - I think this would be best suited to a new question. – ziesemer Jan 24 '12 at 05:42
  • I've added it here: http://stackoverflow.com/questions/8982551/getting-java-io-ioexception-when-running-junit-test-case-in-eclipse-continued – dale Jan 24 '12 at 05:49
0

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

Arun
  • 3,440
  • 11
  • 60
  • 108