简体   繁体   English

使用 Eclipse 远程运行 Junit 测试,就像在本地运行一样

[英]Running a Junit test remotely, as if it were running locally, using Eclipse

I've search around, read relevant questions on this site and others, but have failed to find a solution.我四处搜索,阅读了本网站和其他网站上的相关问题,但未能找到解决方案。 It strikes me odd that one does not exist so let me detail my question here:让我感到奇怪的是,一个不存在所以让我在这里详细说明我的问题:

I use Junit4 + Eclipse regularly to test my code.我经常使用 Junit4 + Eclipse 来测试我的代码。 In some cases, certain tests can take a lot of CPU and/or memory, rendering my workstation unusable for the duration of the test.在某些情况下,某些测试可能会占用大量 CPU 和/或内存,导致我的工作站在测试期间无法使用。 This is a pain I'm trying to solve.这是我试图解决的痛苦。

I'm looking to get the exact same behavior but through a remote server.我希望通过远程服务器获得完全相同的行为。 I want:我想要:

  1. To still be able to set breakpoints and debug my app.仍然能够设置断点和调试我的应用程序。
  2. To see how the tests progress using the Junit view in Eclipse.使用 Eclipse 中的 Junit 视图查看测试的进展情况。
  3. Click on a button have the tests started (build process and copying of files is allowed, but only if efficient).单击按钮开始测试(允许构建过程和复制文件,但前提是有效)。

In my mind I envision something that rsyncs the files to the remote server, starts the java process there with the exact same arguments as it would on my local machine, makes the debug port available (not just localhost) and has eclipse hook up to it to have both debug and junit view working.在我的脑海中,我设想了一些将文件 rsync 到远程服务器的东西,在那里使用与在我的本地机器上完全相同的参数启动 java 进程,使调试端口可用(不仅仅是本地主机)并有 eclipse 连接到它让调试和junit视图都工作。

How can I get this done?我怎样才能做到这一点?

Several leading questions that may help us find a solution:可以帮助我们找到解决方案的几个主要问题:

  1. How does Eclipse communicate with the java process when run locally (for both debug purposes AND the Junit view)? Eclipse 在本地运行时如何与 java 进程通信(用于调试目的和 Junit 视图)?
  2. How can I involve myself in the process of spawning the java process for the JUnit testing so I can copy the required files over to a remote server?我如何让自己参与为 JUnit 测试生成 java 进程的过程,以便我可以将所需的文件复制到远程服务器?
  3. How can I make the process spawn remotely instead of locally?如何使进程在远程而不是本地生成?
  4. How can I have Eclipse hook up to the remote host instead of the localhost?如何让 Eclipse 连接到远程主机而不是本地主机?

The easiest would be to invoke command line JUnit runner on remote mashine using the following command:最简单的方法是使用以下命令在远程 mashine 上调用命令行 JUnit运行程序:

java -Xdebug -Xrunjdwp:transport=dt_socket,address=8998,server=y,suspend=y -cp ... org.junit.runner.JUnitCore <test class name>

So, it will wait til you attach remote debugger from Eclipse at port 8998.因此,它将等到您从 Eclipse 端口 8998 附加远程调试器。

You can also use Eclipse's Target Management tools to transfer files to remote system and launch remote commands.您还可以使用 Eclipse 的目标管理工具将文件传输到远程系统并启动远程命令。 There is several tutorials on the project page.项目页面上有几个教程。

为此尝试 vs code 远程 ssh 扩展。

You could set up a jenkins CI server, sync your code via git (or just copy using ftp or something), execute the test in a jenkins job triggered by a git-hook or through some script.你可以设置一个 jenkins CI 服务器,通过 git 同步你的代码(或者只是使用 ftp 或其他东西复制),在一个由 git-hook 或通过一些脚本触发的 jenkins 作业中执行测试。 Then remote debug into the running test process like Eugene Kuleshov suggested.然后像 Eugene Kuleshov 建议的那样远程调试到正在运行的测试过程中。 This process could be automated by an ant-script which you invoke from eclipse.这个过程可以由你从 eclipse 调用的 ant 脚本自动化。 There should be a mylin connector ( for example ) through which you can monitor the running tests.应该有一个 mylin 连接器(例如),您可以通过它来监视正在运行的测试。 I don't know if it is possible using the standard JUnit view of eclipse to see the running tests without using some custom plugins (if any exist).我不知道是否可以使用 Eclipse 的标准 JUnit 视图来查看正在运行的测试而不使用一些自定义插件(如果存在的话)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM