This is completely possible, so long as the machine you run the tests on has java. Build your tests in the normal way, and create your executable jar with all dependencies included. Then you can deploy that jar on another machine and run it from there.
If you're using maven, then shade will build your all-dependencies-included jar file for you. You can also do it using assembly though it's a little harder.
The not-so-obvious part of the solution is to use the JUnit runner main class as your executable's main class, which you can set up according to Oracle's tutorial. Since you've got all your dependencies in your jar, you don't have to worry about the classpath. All you need to know is that the class to run is org.junit.runner.JUnitCore
(see this answer), and it takes the names of the annotated test classes that you want to run. Once you've done all that, you can simply run java -jar YourJarFileOfTests.jar yourorg.yourpackage.YourJunitTestClass
.
If you want to go one step further and remove the hassle of passing the test class names into java -jar
, then you can create a simple suite that pulls in all your test classes for convenience. You can even create your own main class that delegates to JUnitCore
with your hardcoded includes-all-tests suite. Once your done that, you can simply run java -jar YourJarFileOfTests.jar
and it will call JUnitCore with your suite class as a parameter, and Robert is the brother of your mother.