2

I have a web application packaged in .war archive. It also contains unit test classes. I want to deploy this application on different machines and each time run test from the command line. How can I do this taking into account that tests are in .war? I use Tomcat7. I do not consider usage of Ant.

Thank you!

user1379574
  • 689
  • 4
  • 11
  • 23
  • Do you want to run your junit tests locally against the different wars or on the actual server? (it sounds like the later.) Also, why did you rule out Ant? The answer to this will avoid suggestions of something similar - like a shell script.... – Jeanne Boyarsky Jul 16 '12 at 00:57
  • yes, the second variant..ok, if I accept ant, how to do this from .war? – user1379574 Jul 16 '12 at 09:58
  • Related question: http://stackoverflow.com/questions/2235276/how-to-run-junit-testcases-from-command-line – Mark O'Connor Jul 16 '12 at 16:06

1 Answers1

1

You'll need a copy of the junit jar to run the test runner. Assuming it's already inside the WAR file it can be retrieved as follows:

unzip myapp.war WEB-INF/lib/junit-4.10.jar

Junit can then be run as follows:

java -cp WEB-INF/lib/junit-4.10.jar:myapp.war org.junit.runner.JUnitCore [test class name goes here]

Note:

  • If your tests need any other jars packaged inside the WAR they'll need to pulled out as well.
Mark O'Connor
  • 76,015
  • 10
  • 139
  • 185