Vincent Roye
Vincent Roye

Reputation: 2841

Run JUnit Test from a java web application

Is it possible to run JUnit Tests from a java web application (on a Tomcat server) ?

How can I with a click on a link, launch the instantiation of an object ? or the call to a method ?

Thank you very much.

Best Regards.

Upvotes: 2

Views: 7819

Answers (2)

Paul Croarkin
Paul Croarkin

Reputation: 14675

There a number of JUnit-based frameworks that can assist with web testing.

Jwebunit

Canoo Webtest

HttpUnit

HtmlUnit

Upvotes: 0

Dave Newton
Dave Newton

Reputation: 160181

Sure, although I'm not sure why you'd want to.

See the cookbook example, nutshell:

org.junit.runner.JUnitCore.runClasses(TestClass1.class, ...);

Obviously you'd need to deploy your test classes so they're available on the classpath, and convert from a string class name to an actual Class.

You'd likely also need to scan for annotations or convention-based class names; there are a variety of ways to do that including things like the reflections library.

IMO it'd be easier to set up a continuous integration (CI) server like Jenkins or CruiseControl etc. and get a complete package, but it depends on what your needs actually are.

Upvotes: 5

Related Questions