测量远程脚本测试的代码覆盖率 [英] Measure code coverage for remote scripting tests

查看:67
本文介绍了测量远程脚本测试的代码覆盖率的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个部署在 JBoss 5.1, PowerShell 编写了脚本进行测试.这些脚本使用Web服务访问应用程序.

We have an application which is deployed on JBoss 5.1, JDK 1.6. We also have scripts written in PowerShell for testing. These scripts access the application using a web-service.

我想检查脚本的代码覆盖率.有任何想法吗?我看到的大多数工具都在检查 JUnit 测试覆盖率,但我看不出我们如何可以使用它们.

I would like to check the code coverage of the scripts. Any ideas? Most of the tools I saw are checking a JUnit test coverage and I don't see how we can use them.

推荐答案

AFAIK,所有代码覆盖工具都使用相同的概念(我将省略报告和检查部分):

AFAIK, all code coverage tools use the same concept (I'll omit the reporting and checking part):

  1. 首先检测代码(即放置标记).
  2. 然后运行测试以执行检测出的代码(以激活标记并收集数据).

第二步,通常的用例确实是运行JUnit测试,但是您的测试不必是JUnit测试.实际上,它们甚至不必自动化.

For the second step, the common use case is indeed to run JUnit tests but your tests don't have to be JUnit tests. Actually, they don't even have to be automated.

检测到的代码不必在单元测试的上下文中执行,可以将其打包在WAR/EAR中并部署在容器上(这将需要更多的工作).

And the instrumented code doesn't have to be executed in the context of a unit test, it can be packaged in a WAR/EAR and deployed on a container (this will just require a bit more work).

对于Cobertura,这是我们可以在常见问题中阅读的内容:

For Cobertura, this is what we can read in the Frequently Asked Questions:

将Cobertura与Web应用程序一起使用

我有使用的自动测试 HttpUnit/HtmlUnit/Empirix/Rational 机器人,我可以使用Cobertura吗?

Using Cobertura with a Web Application

I have automated tests that use HttpUnit/HtmlUnit/Empirix/Rational Robot, can I use Cobertura?

是的!这个过程有点多 涉及,但概念是相同的. 您编译的第一个乐器 类.然后创建您的战争文件. 然后将war文件部署到您的 应用程序服务器(Tomcat,JBoss, WebLogic,WebSphere等).现在运行 您的测试.

Yes! The process is a bit more involved, but the concept is the same. First instrument your compiled classes. Then create your war file. Then deploy the war file into your application server (Tomcat, JBoss, WebLogic, WebSphere, etc). Now run your tests.

在访问您的班级时,他们 将在以下位置创建"cobertura.ser"文件 磁盘.您可能需要挖掘一个 有点找到它. Cobertura提出了 以它认为是 当前工作目录.通常 这是目录 应用程序服务器从以下位置启动 (例如,C:\ Tomcat \ bin)注意: 此文件未写入磁盘 直到应用程序服务器退出. 有关如何解决此问题的信息,请参见下文.

As your classes are accessed, they will create a "cobertura.ser" file on the disk. You may need to dig around a bit to find it. Cobertura puts this file in what it considers to be the current working directory. Typically this is the directory that the application server was started from (for example, C:\Tomcat\bin) Note: This file is not written to the disk until the application server exits. See below for how to work around this.

现在您知道 cobertura.ser文件是,您应该 修改您的部署步骤,使其 将原始cobertura.ser移至 您的适当目录 应用程序服务器,然后将其移动 完成测试后返回.然后跑 cobertura报告.

Now that you know where the cobertura.ser file is, you should modify your deploy step so that it moves the original cobertura.ser to the appropriate directory in your application server, and then moves it back when finished testing. Then run cobertura-report.

[...]

对于Emma,这就是文档所说的:

For Emma, this is what the documentation says:

3.11.如何在{WebLogic,Websphere,Tomcat,JBoss,...}中使用EMMA?

首先,您几乎不可能对成熟的J2EE容器使用即时模式(emmarun).原因在于许多J2EE功能都需要特殊的类加载,这将在EMMA仪器类加载器之外进行.服务器可能运行正常,但是您可能没有覆盖数据.

First of all, there is little chance that you will be able to use the on-the-fly mode (emmarun) with a full-blown J2EE container. The reason lies in the fact that many J2EE features require specialized classloading that will happen outside of EMMA instrumenting classloader. The server might run fine, but you will likely get no coverage data.

因此,正确的过程是在部署之前对类进行检测(脱机​​模式).脱机检测始终遵循相同的编译/仪器/程序包/部署/获取覆盖率/生成报告顺序.请按照下列步骤操作:

Thus, the correct procedure is to instrument your classes prior to deployment (offline mode). Offline instrumentation always follows the same compile/instrument/package/deploy/get coverage/generate reports sequence. Follow these steps:

  1. 使用EMMA的instr工具来检测所需的类.可以在包装之前将其作为编译后的步骤进行.但是,许多用户还发现让EMMA直接处理罐子很方便(使用覆盖模式就地就地进行处理,或者以全拷贝模式通过创建所有的单独检测副本);
  2. 正常进行J2EE打包,但不要在此级别(即,在.war,.ear等内部)中将emma.jar作为lib包含在内.
  3. 找到容器使用的任何JRE,然后将emma.jar复制到其/lib/ext目录中.如果不可能,则将emma.jar添加到服务器类路径(以特定于服务器的方式);
  4. 部署您的检测类,.jars,.wars,.ears等,并通过客户端测试用例或以交互方式或以任何方式对J2EE应用程序进行练习/测试;
  5. 要获取Coverage转储文件,您有3个选项,其中存在哪些选项可控制EMMA何时转储运行时coverage数据?强烈建议您将v2.1中提供的ctl工具与coverage.get控制命令配合使用.
  1. use EMMA's instr tool to instrument the desired classes. This can be done as a post-compilation step, before packaging. However, many users also find it convenient to let EMMA process their jars directly (either in-place, using overwrite mode, or by creating separate instrumented copies of everything, in fullcopy mode);
  2. do your J2EE packaging as normal, but do not include emma.jar as a lib at this level, that is, within your .war, .ear, etc;
  3. locate whichever JRE is used by the container and copy emma.jar into its /lib/ext directory. If that is impossible, add emma.jar to the server classpath (in a server-specific way);
  4. deploy your instrumented classes, .jars, .wars, .ears, etc and exercise/test your J2EE application via your client-side testcases or interactively or whichever way you do it;
  5. to get a coverage dump file, you have three options described in What options exist to control when EMMA dumps runtime coverage data?. It is highly recommended that you use coverage.get control command with the ctl tool available in v2.1.

对于三叶草,请查看使用分布式应用程序页面

For clover, check the Working with Distributed Applications page.

这篇关于测量远程脚本测试的代码覆盖率的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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