从Java Web应用程序运行JUnit Test [英] Run JUnit Test from a java web application

查看:99
本文介绍了从Java Web应用程序运行JUnit Test的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以从Java Web应用程序(在Tomcat服务器上)运行JUnit测试?

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 ?

非常感谢您.

最好的问候.

推荐答案

可以,尽管我不确定您为什么要这么做.

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

请参见烹饪书示例,简而言之:

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

显然,您需要部署测试类,以便它们在类路径中可用,并将其从字符串类名称转换为实际的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.

您可能还需要扫描注释或基于约定的类名称;有多种方法可以做到这一点,包括 reflections 库.

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,设置像 Jenkins CruiseControl 等,并获得完整的软件包,但这取决于您的实际需求.

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.

这篇关于从Java Web应用程序运行JUnit Test的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆