windows 无法在 Eclipse 中运行 junit 测试
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/424392/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Unable to run junit tests in Eclipse
提问by Bill Comer
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.socketConnect(Native Method) at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333) at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java: 195) 在 java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182) 在 java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366) 在 java.net.Socket.connect(Socket.java:520) 在 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.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:377) 在 org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:377) .主要(RemoteTestRunner.java:196)
The port number varies. I found a forum post that told me follow this http://support.microsoft.com/kb/135982But 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
我们都在通过 ISA 服务器/代理连接到 Internet 的基于 Microsoft XP 的机器上。我正在运行 Eclipse 3.3.3 和 MyEclipse 6.0.1
Any ideas please ?
请问有什么想法吗?
回答by Bill Comer
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 时都停止运行,但还没有看到合适的选项。
回答by guerda
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?
奇怪的世界...日志文件中有任何提示吗?
回答by VonC
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:
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.
我希望你能找到一个明确的原因。
回答by guerda
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(进程间通信)进行通信,更好的说法是:通过 TCP。要成功运行它,您必须修复网络驱动程序。
Try to reinstall TCP/IP protocols or turn it back to a system restore point.
尝试重新安装 TCP/IP 协议或将其转回系统还原点。
Good luck!
祝你好运!