Inside my IDE (Eclipse or NetBeans, doesn't matter), i have some TestNG testclasses (But my question also refers to remote JUnit tests), which are Integration tests. These tests need an integration server to run, they cannot be run on a local machine. They need the complete environment of the integration server - not only JavaEE container related stuff (=> no Arquillian nor JEEUnit).
Now I want to be able to run these tests from within my IDE (Eclipse) - preferrably with the TestNG Plugin - but when I launch them they should actually be run on the remote integration server.
Is it possible to launch integration tests on a remote server from within my IDE? I like the idea of having some kind of Agent on the remote Server which waits for test-requests and executes them. But as I said, it would be nice if this runs from inside the TestNG Plugin.
Do I need some kind of workaround, for example Ant scripts (hopefully not) or some Maven magic? What are the best practices?
I know I could also create Webservices for my application, then I can call them from local unit tests. But I'd like to know if there are also possibilities without Webservices.
You can execute your existing JUnit test cases using TestNG. TestNG can automatically recognize and run JUnit tests, so that you can use TestNG as a runner for all your existing tests and write new tests using TestNG.
Running JUnit. JUnit tests can be run directly in IntelliJ, but they can also be run in other IDEs like Eclipse, NetBeans, or even the command line.
TestNG integration test example. TestNG is a great test framework. At most of the time is used for unit test. While it can also be used for integration test.
How you will accomplish this depends a lot on what integration server and IDE you're using, and what you're application is. I'll assume you're using Eclipse; and I'll assume you're using Jenkins, since it will IMO be the easiest to get it to do what you want.
Most of this will work out of the box. However, there is a little bit that will require a some of additional work.
You'll want to do the following:
Now comes the slightly more complicated part of hooking up 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 it should be very simple to achieve with a custom script. All the script has to do is:
$programFile
http://<your-jenkins-server>:8080/<integrated-testing-job-name>/buildwithparameters?TestingProgram=$programFile
You can read up more on triggering Jenkins remote builds with parameters in the jenkins docs.
The script that accomplishes these steps can be pretty much anything. Given that you want to ultimately incorporate it into your IDE, it seems like the most logical choices would be an ant script or an Eclipse plugin. Neither would be too complicated - the ant script would just do those steps, and you could import the ant script into an Eclipse project specifically for doing testing - and a plugin could just add a menu item which, when run within a project, would execute the above steps for that project.
NOTE: There are actually several different ways to trigger a build with parameters using Jenkins. For example, you can do a POST request, use json to pass the parameter as described in the jenkins docs I linked to, use the Jenkins CLI, etc. Not all of them work with file parameters, but you would use them all in a very similar way - as a step in your custom script, you would execute a remote build on Jenkins, and pass the file you want to use to test with. For example, the explanation I gave assumes that the testing file is very small; if that's not the case, you might want to do a POST request instead. If you run into problems using one method, it should be pretty easy to switch it to use a different method that works better.
Unfortunately I do not have a ready solution but I think I can give you some tips since I spent some time thinking about this.
I do not know about TestNG but JUnit has ability to plugin your own test executor. I am sure that TestNG has appropriate functionality. So, find it and be familiar with it. Since you can control how your test is being invoked you can even do something else instead of invoking the test case's methods. For example call some remote API that will make the test to run remotely.
Obviously it can be web service that makes remote Agent (according to your suggestion) to run test on remote machine. It is fine, but I like agent-less or semi agent-less solutions more. What do I mean? If for example your remote machine is Unix you can perform SSH or Telnet connection and run command line. In this case you can create mvn or ant script, copy to remote machine using ssh and then run it. The script will run your tests. So it is almost agent less. You just require java installation and SSH support.
If remote machine is windows you can use either Telnet or WMI. So, if security is not an issue but you need cross platform support use Telnet.
Please do not hesitate to contact me if you need more assistance concerning SSH/Telnet.
I haven't done it myself (my tests are local), but here are some stuff that could work:
In my solution, I will lunch a local JNDI server and add a remote object (an object implement the Remote interface), then you could use the remote object to sync your local IDE and remote server or other place.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With