Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JUnit java.net.ConnectException

I'm pretty new in Java, so don't be rude ;-) I got a task to do and there are some JUnit-Tests to verify my solution. When I'm trying to run them, it takes some time and then I get the following errors:

Could not connect to:  : 51219          
java.net.ConnectException: connect: Address is invalid on local machine, or port is not valid on remote machine
    at java.net.DualStackPlainSocketImpl.connect0(Native Method)
    at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)
    at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
    at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
    at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
    at java.net.PlainSocketImpl.connect(Unknown Source)
    at java.net.SocksSocketImpl.connect(Unknown Source)
    at java.net.Socket.connect(Unknown Source)
    at java.net.Socket.connect(Unknown Source)
    at java.net.Socket.<init>(Unknown Source)
    at java.net.Socket.<init>(Unknown Source)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.connect(RemoteTestRunner.java:570)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:381)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

Here's what I use:

  • Windows 8
  • JRE 7
  • JUnit 4
  • Eclipse Classic 4.2.1

Can you help me with this?

like image 392
Matteo Avatar asked Jul 02 '26 01:07

Matteo


1 Answers

It seems that your Unit test is trying to connect to port 51219 which is not possible on your local machine.
Try to start a local server, or "mock" the server connection.

like image 149
AlexWien Avatar answered Jul 03 '26 15:07

AlexWien