0

I have a spring boot project where I'm using gradle for dependency management. I copy the project jar to a remote machine. There I want to run the unit tests using my jar file. I'm using junit for running the unit tests. How do I run the unit tests from my jar file in the remote machine?

cyberman123
  • 412
  • 5
  • 14
  • Have a look to this SO question - https://stackoverflow.com/questions/2235276/how-to-run-junit-test-cases-from-the-command-line Just fyi: Not sure about your use-case, but generally your build should run unit-test before generating the Jar file. – Haran Jan 14 '20 at 07:47

1 Answers1

0

There is something unclear in your understanding of Jar / unit testing.

Unit tests are made to help building your application in a proper way. You are able to perfomr some tests against your classes. To relate this to a JAR file, your unit tests are here to make sure you build a JAR that "works" (i.e passes your tests).

There is therefor no reason to try executing your tests on the remote machine. Besides, if you open your Jar file (which is just a Zip), you will see that your test classes are not inside. That is because, in a Jar, you only want classes that will be used on production.

Instead, asks you this : - What are you trying to achieve but running unit tests on the remote machine ? - Isn't it more like a integration or end to end tests ? Basically, what you want is : deploy the Jar on the server an make sure it still working.

If you really run your tests on your remote machine, then you can go check the link in your comment : How to run JUnit test cases from the command line. I wouldn't recomment, because, like I said, there is a few chances (depends on your configuration of course) that your test classes are embedded on your jar.

Hope it helps you thinking. Don't hesitate to update your posts to add more information.

RUARO Thibault
  • 2,672
  • 1
  • 9
  • 14