无法在Eclipse中运行junit测试

时间:2023-02-05 10:40:33

I and my colleagues have an intermittent problem running junit tests or tomcat from within Eclipse.

我和我的同事在Eclipse中运行junit测试或tomcat时出现间歇性问题。

Sometimes the tests will run. Sometimes they will not. There appears to be no pattern and we are not in sync. IE mine might run and others will fail.

有时测试会运行。有时他们不会。似乎没有模式,我们没有同步。我的IE可能会运行而其他人会失败。

Stopping/starting Eclipse can resolve the issue (sometimes). Pulling out the network cable ALWAYS resolves the problem (while it is out).

停止/启动Eclipse可以解决问题(有时)。拔出网线始终解决问题(当它出局时)。

When it fails the following happens. On trying to run the class the Console screen appears with the red box. The console screen stays blank for about 30 seconds and then the following appears:

当它失败时会发生以下情况。在尝试运行该类时,控制台屏幕显示红色框。控制台屏幕保持空白约30秒,然后出现以下内容:

Could not connect to: : 2083
java.net.ConnectException: Connection refused: connect at java.net.PlainSocketImpl.socketConnect(Native Method) at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333) at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195) at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182) at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366) at java.net.Socket.connect(Socket.java:520) at java.net.Socket.connect(Socket.java:470) at java.net.Socket.(Socket.java:367) at java.net.Socket.(Socket.java:180) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.connect(RemoteTestRunner.java:560) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:377) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)

无法连接到:: 2083 java.net.ConnectException:连接被拒绝:在java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)java.net.PlainSocketImpl上的java.net.PlainSocketImpl.socketConnect(Native Method)连接.connectToAddress(PlainSocketImpl.java:195)位于java.net.SocksSocketImpl.connect(PlainSocketImpl.java:182),java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366),java.net.Socket.connect(Socket。 java:520)at java.net.Socket.connect(Socket.java:470)at java.net.Socket。(Socket.java:367)at java.net.Socket。(Socket.java:180)at org。 eclipse.jdt.internal.junit.runner.RemoteTestRunner.connect(RemoteTestRunner.java:560)位于org.eclipse.jdt的org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:377)。 internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)

The port number varies. I found a forum post that told me follow this http://support.microsoft.com/kb/135982 But this did not work.

端口号有所不同。我找到了一个论坛帖子,告诉我关注此http://support.microsoft.com/kb/135982但这不起作用。

We are all on Microsoft XP based machines connecting to the internet via an ISA server/proxy. I am running Eclipse 3.3.3 and MyEclipse 6.0.1

我们都在基于Microsoft XP的机器上通过ISA服务器/代理连接到互联网。我正在运行Eclipse 3.3.3和MyEclipse 6.0.1

Any ideas please ?

有什么想法吗?

4 个解决方案

#1


I have concentrated on junit instead of tomcat as it is much quicker & easier to reproduce. Yep I had seen the McQueeney link with no luck.

我专注于junit而不是tomcat,因为它更快更容易重现。是的,我看过McQueeney链接没有运气。

We have done some more digging and interestingly when you run junit from Eclipse, Eclipse decides to go & check for updates, Yes that's right - everytime you run a junit (& I guess tomcat and others).

当你从Eclipse运行junit时,我们已经做了一些挖掘和有趣的事情,Eclipse决定去检查更新,是的,这是正确的 - 每次你运行junit(我猜tomcat和其他人)。

We removed a colleague's access restrictions to the WWW through the ISA server and low & behold the problem disappeared.

我们通过ISA服务器删除了同事对WWW的访问限制,并且看到问题消失了。

We are still monitoring this to see if it is the solution. Watch this space.

我们仍然在监视它,看看它是否是解决方案。关注此空间。

I have tried looking through the Eclipse set up to see if I can stop it trundling off everytime to the WWW but have not seen a suitable option yet.

我已经尝试通过Eclipse设置查看是否可以阻止它每次都到WWW,但还没有看到合适的选项。

#2


Some suggestions...:

Did you look at tomcat logs ?

你看过tomcat的日志吗?

Do you see in them some ClientAbortException: java.net.SocketException: Broken pipe. ?

你在其中看到一些ClientAbortException:java.net.SocketException:Broken pipe。 ?

It looks like the server thinks the client is closing the connection at times. And like the client is getting the connection reset by the server (connection reset), and the server is not listening sometimes (connection refused).

看起来服务器认为客户端有时会关闭连接。并且像客户端正在通过服务器重置连接(连接重置),并且服务器有时没有监听(连接被拒绝)。

If you are testing from behind a firewall/proxy server, you may need to provide TomCat with the firewall/proxy server hostname and port number.

如果您从防火墙/代理服务器后面进行测试,则可能需要向TomCat提供防火墙/代理服务器主机名和端口号。

Restarting eclipse should be enough:

重启eclipse应该足够了:

Apparently the JUnit runner thread in Eclipse attaches to an Eclipse server thread to run the tests. It would seem the client thread was trying to connect to the wrong port (3393) or that the server thread that had been listening on port 3393 for runtime requests failed.

显然,Eclipse中的JUnit运行程序线程附加到Eclipse服务器线程以运行测试。似乎客户端线程正在尝试连接到错误的端口(3393),或者已经在端口3393上侦听运行时请求的服务器线程失败。

The solution McQueeney found is here (thank you Archive.org!)

McQueeney发现的解决方案就在这里(谢谢Archive.org!)

One suggestion I find interesting is:

我觉得有趣的一个建议是:

I had to change the jre that my Eclipse project uses to make sure that JUnit and my project were using the same jre. After a restart of Eclipse the error was gone.

我不得不改变我的Eclipse项目使用的jre,以确保JUnit和我的项目使用相同的jre。重新启动Eclipse后,错误消失了。

I hope you will find a definitive cause for this.

我希望你能找到一个明确的原因。

#3


I had the same problem, when my network driver was broken.

当我的网络驱动程序被破坏时,我遇到了同样的问题。

JUnit und Eclipse communicate via ICP (InterProcess Communication), better said: via TCP. To run it successfully, you have repair your network drivers.

JUnit和Eclipse通过ICP(InterProcess Communication)进行通信,更好地说:通过TCP。要成功运行它,您需要修复网络驱动程序。

Try to reinstall TCP/IP protocols or turn it back to a system restore point.

尝试重新安装TCP / IP协议或将其转回系统还原点。

Good luck!

#4


So your JUnit only works, if there's a connection to the internet? Or was it a one time action and now, it works without an internet connection?

所以你的JUnit只有在与互联网连接的情况下才有效吗?或者它是一次性动作,现在,它没有互联网连接吗?

Strange world... Are there any hints in a log file?

奇怪的世界......日志文件中是否有任何提示?

#1


I have concentrated on junit instead of tomcat as it is much quicker & easier to reproduce. Yep I had seen the McQueeney link with no luck.

我专注于junit而不是tomcat,因为它更快更容易重现。是的,我看过McQueeney链接没有运气。

We have done some more digging and interestingly when you run junit from Eclipse, Eclipse decides to go & check for updates, Yes that's right - everytime you run a junit (& I guess tomcat and others).

当你从Eclipse运行junit时,我们已经做了一些挖掘和有趣的事情,Eclipse决定去检查更新,是的,这是正确的 - 每次你运行junit(我猜tomcat和其他人)。

We removed a colleague's access restrictions to the WWW through the ISA server and low & behold the problem disappeared.

我们通过ISA服务器删除了同事对WWW的访问限制,并且看到问题消失了。

We are still monitoring this to see if it is the solution. Watch this space.

我们仍然在监视它,看看它是否是解决方案。关注此空间。

I have tried looking through the Eclipse set up to see if I can stop it trundling off everytime to the WWW but have not seen a suitable option yet.

我已经尝试通过Eclipse设置查看是否可以阻止它每次都到WWW,但还没有看到合适的选项。

#2


Some suggestions...:

Did you look at tomcat logs ?

你看过tomcat的日志吗?

Do you see in them some ClientAbortException: java.net.SocketException: Broken pipe. ?

你在其中看到一些ClientAbortException:java.net.SocketException:Broken pipe。 ?

It looks like the server thinks the client is closing the connection at times. And like the client is getting the connection reset by the server (connection reset), and the server is not listening sometimes (connection refused).

看起来服务器认为客户端有时会关闭连接。并且像客户端正在通过服务器重置连接(连接重置),并且服务器有时没有监听(连接被拒绝)。

If you are testing from behind a firewall/proxy server, you may need to provide TomCat with the firewall/proxy server hostname and port number.

如果您从防火墙/代理服务器后面进行测试,则可能需要向TomCat提供防火墙/代理服务器主机名和端口号。

Restarting eclipse should be enough:

重启eclipse应该足够了:

Apparently the JUnit runner thread in Eclipse attaches to an Eclipse server thread to run the tests. It would seem the client thread was trying to connect to the wrong port (3393) or that the server thread that had been listening on port 3393 for runtime requests failed.

显然,Eclipse中的JUnit运行程序线程附加到Eclipse服务器线程以运行测试。似乎客户端线程正在尝试连接到错误的端口(3393),或者已经在端口3393上侦听运行时请求的服务器线程失败。

The solution McQueeney found is here (thank you Archive.org!)

McQueeney发现的解决方案就在这里(谢谢Archive.org!)

One suggestion I find interesting is:

我觉得有趣的一个建议是:

I had to change the jre that my Eclipse project uses to make sure that JUnit and my project were using the same jre. After a restart of Eclipse the error was gone.

我不得不改变我的Eclipse项目使用的jre,以确保JUnit和我的项目使用相同的jre。重新启动Eclipse后,错误消失了。

I hope you will find a definitive cause for this.

我希望你能找到一个明确的原因。

#3


I had the same problem, when my network driver was broken.

当我的网络驱动程序被破坏时,我遇到了同样的问题。

JUnit und Eclipse communicate via ICP (InterProcess Communication), better said: via TCP. To run it successfully, you have repair your network drivers.

JUnit和Eclipse通过ICP(InterProcess Communication)进行通信,更好地说:通过TCP。要成功运行它,您需要修复网络驱动程序。

Try to reinstall TCP/IP protocols or turn it back to a system restore point.

尝试重新安装TCP / IP协议或将其转回系统还原点。

Good luck!

#4


So your JUnit only works, if there's a connection to the internet? Or was it a one time action and now, it works without an internet connection?

所以你的JUnit只有在与互联网连接的情况下才有效吗?或者它是一次性动作,现在,它没有互联网连接吗?

Strange world... Are there any hints in a log file?

奇怪的世界......日志文件中是否有任何提示?