简体   繁体   中英

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. In some cases, certain tests can take a lot of CPU and/or memory, rendering my workstation unusable for the duration of the test. 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.
  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.

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)?
  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?
  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?

The easiest would be to invoke command line JUnit runner on remote mashine using the following command:

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.

You can also use Eclipse's Target Management tools to transfer files to remote system and launch remote commands. 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. Then remote debug into the running test process like Eugene Kuleshov suggested. This process could be automated by an ant-script which you invoke from eclipse. There should be a mylin connector ( for example ) through which you can monitor the running tests. 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).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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