Running test tests TestNG / JUnit on a remote server from the IDE

Inside my IDE (Eclipse or NetBeans, it doesn't matter) I have TestNG test classes (but my question also relates to remote JUnit tests) which are integration tests. For these tests, you need an integration server to run, they can not be run on the local machine. They need a complete integration server environment β€” not just container-related JavaEE objects (=> no Arquillian or JEEUnit).

Now I want to be able to run these tests from my IDE (Eclipse) - preferably using TestNG Plugin, but when I run them, they should actually run on the remote integration server.

Is it possible to run integration tests on a remote server from my IDE? I like the idea of ​​having some kind of Agent on a remote server that is waiting for test requests and executing them. But, as I said, it would be nice if this happened from inside the TestNG plugin.

Do I need some workaround, like Ant scripts (hopefully not) or some Maven Moors? What are the best practices?

I know that I could also create Web services for my application, then I can name them from local tests. But I would like to know if there are opportunities without web services.

+8
java java-ee junit integration-testing testng
source share
4 answers

How you do this depends on which integration server and IDE you use and what you use. Suppose you are using Eclipse; and I will assume that you are using Jenkins , as this will be IMO the easiest to get it to do what you want.

Most of this will work out of the box. However, there is little that will require some extra work.

You want to do the following:

  • Set up Jenkins by naming something like "Integrated Testing" (the name doesn't matter). Configure it to run the tests you want to run from the IDE and to allow remote computers to run assemblies.
  • Make this task parameterized and add a file parameter. Suppose this is called a "TestingProgram". This will be the program that the task will check.
  • The Integrated Testing job task uses the TestingProgram file to run tests. If the program requires more than one file, then suppose that it is a zip file containing all the necessary files.
  • Set up your Eclipse project to create the same files (s) that are awaiting integration test results (I assume this is already happening, as it seems to be creating some kind of bin version of your program)

Now comes the slightly more complicated part of connecting Eclipse to Jenkins. Unfortunately, I don’t think there are any preexisting tools that will do exactly what you want. The good news is that with a custom script this should be very simple. All script should:

  • If your program has several required files, and eclipse does not do this yet, you will need to pin these files to
  • He will need to take the file and read it in some variable, and then base64 encode it. There are many libraries that will take care of this for you, like this one . Suppose this file is read into a variable named $programFile
  • He will need to send an HTTP request to http://<your-jenkins-server>:8080/<integrated-testing-job-name>/buildwithparameters?TestingProgram=$programFile

You can read more about running remote Jenkins builds with options in denkins docs .

The script that follows these steps can be almost anything. Given that you want to eventually include it in your IDE, it seems that the most logical choice would be an ant script or an Eclipse plugin. None of them will be too complicated: the ant script will perform these actions, and you can import the ant script into the Eclipse project specifically for testing - and the plugin can simply add a menu item that, when launched as part of the project, will perform the above steps to do this project.

NOTE. There are several different ways to start an assembly with parameters using Jenkins. For example, you can execute a POST request, use json to pass the parameter, as described in the jenkins docs I am linked to, use the Jenkins CLI, etc. Not all of them work with file parameters, but you will use them all in one very similarly - as a step in a user script, you must perform remote assembly on Jenkins and transfer the file that you want to use for testing. For example, the explanation I gave suggests that the test file is very small; if this is not the case, you may want to execute a POST request. If you are having problems using one method, it's pretty easy to switch it to use another method that works better.

+4
source share

Unfortunately, I do not have a ready-made solution, but I think I can give you some advice, since I thought about this for some time.

I do not know about TestNG, but JUnit has the ability to connect its own test executor. I am sure that TestNG has the corresponding functionality. So, find him and get to know him. Since you can control how your test is called, you can even do something else instead of calling test case methods. For example, call some remote API that will make the test work remotely.

Obviously, this could be a web service that a remote agent does (as per your suggestion) to run a test on a remote machine. This is normal, but I no longer need agents or semi-agents. What I mean? If, for example, your remote computer is Unix, you can make an SSH or Telnet connection and run a command prompt. In this case, you can create an mvn or ant script, copy it to the remote machine using ssh and then run it. The script will do your tests. So this is almost an agent less. You just need java installation and SSH support.

If the remote machine is windows, you can use Telnet or WMI. So, if security is not a problem, but you need cross-platform support, use Telnet.

Please feel free to contact me if you need further assistance regarding SSH / Telnet.

+2
source share

I did not do this myself (my tests are local), but here are some things that might work:

  • Cargo can be used to start the server and deploy modules in it
  • Test execution can be done using Cactus (fairly old) or JUnitEE. In bothe cases, you run tests using JUnit and run them remotely. Another option is to write tests to interact with a dedicated API on your server that runs tests and reports.
+2
source share

In my solution, I will have lunch on the local JNDI server and add a remote object (the object implements the Remote interface), then you can use the remote object to synchronize the local IDE and the remote server or another place.

+2
source share

All Articles