如何开始编写代码覆盖工具?

时间:2020-12-08 07:30:34

Looking for books or other references that discuss actually how to write a code coverage tool in Java; some of the various techniques or tricks - source vs. byte code instrumentation.

寻找实际讨论如何用Java编写代码覆盖工具的书籍或其他参考资料;一些各种技巧或技巧 - 源代码与字节代码检测。

This is for a scripting language that generates Java byte code under the hood.

这适用于生成Java字节代码的脚本语言。

5 个解决方案

#1


7  

Is your scripting language bytecode generating? Does it generate debug metadata? If so, bytecode instrumentation is probably the way to go. In fact existing tools like will probably work; perhaps with minimal modification (the typical problem is the tools are written to work with Java and assume com.foo.Bar.class corresponds to com/foo/Bar.java. Unwinding that assumption can be tedious.) EMMA is a ClassLoader that does byte-code re-writing for code-coverage collection in Java. The coding style is a little funky, but I recommend reading the source for some ideas.

您的脚本语言字节码是否生成?它是否生成调试元数据?如果是这样,字节码检测可能是要走的路。事实上现有的工具可能会起作用;也许只需要很少的修改(典型的问题是工具是用Java编写的,并假设com.foo.Bar.class对应于com / foo / Bar.java。解开这个假设可能很乏味。)EMMA是一个ClassLoader Java中代码覆盖率集合的字节码重写。编码风格有点时髦,但我建议阅读一些想法的来源。

If your scripting language is interpreted then you will need something higher-level (source level) that hooks into the interpreter.

如果您的脚本语言被解释,那么您将需要一些挂钩到解释器的更高级别(源级别)。

#2


3  

Thxm, Mc! http://asm.objectweb.org/ is another one. Excellent documentation on byte code instrumentation, but nothing "directly" aimed at writing a coverage tool - just some hints or ideas.

嗯,麦克! http://asm.objectweb.org/是另一个。有关字节代码检测的优秀文档,但没有“直接”旨在编写覆盖工具 - 只是一些提示或想法。

#3


2  

You can also get the source from a Open Source code coverage tool and learn from it.

您还可以从开源代码覆盖工具中获取源代码并从中学习。

#4


2  

You might also want to use something like BCEL to analyse which lines of source actually exist in the byte-code. You don't want to report that things like blank lines and comments haven't been covered.

您可能还想使用类似BCEL的东西来分析字节代码中实际存在哪些源代码行。您不希望报告尚未涵盖空白行和注释等内容。

#5


2  

If you're talking about ColdFusion (which I assume you are from the tags) then I'm not sure this is doable but I may be very wrong here...

如果你在谈论ColdFusion(我假设你来自标签)那么我不确定这是否可行,但我可能在这里错了...

IIRC, When CF compiles it essentially compiles into a interpreted form of the CFML as a plain old java source file, this is then compiled into the class. Therefore, any instrumentation that you may have will apply to the intermediary version rather than the CFML itself.

IIRC,当CF编译时,它基本上编译成CFML的解释形式,作为普通的旧java源文件,然后将其编译到类中。因此,您可能拥有的任何工具都将应用于中间版本而不是CFML本身。

Saying that though, Adobe have got the CF debugger now which can step though code, so please prove me wrong - I'd love code coverage in CFML.

尽管如此,Adobe现在已经获得了CF调试器,它可以逐步执行代码,所以请证明我错了 - 我喜欢CFML中的代码覆盖。

#1


7  

Is your scripting language bytecode generating? Does it generate debug metadata? If so, bytecode instrumentation is probably the way to go. In fact existing tools like will probably work; perhaps with minimal modification (the typical problem is the tools are written to work with Java and assume com.foo.Bar.class corresponds to com/foo/Bar.java. Unwinding that assumption can be tedious.) EMMA is a ClassLoader that does byte-code re-writing for code-coverage collection in Java. The coding style is a little funky, but I recommend reading the source for some ideas.

您的脚本语言字节码是否生成?它是否生成调试元数据?如果是这样,字节码检测可能是要走的路。事实上现有的工具可能会起作用;也许只需要很少的修改(典型的问题是工具是用Java编写的,并假设com.foo.Bar.class对应于com / foo / Bar.java。解开这个假设可能很乏味。)EMMA是一个ClassLoader Java中代码覆盖率集合的字节码重写。编码风格有点时髦,但我建议阅读一些想法的来源。

If your scripting language is interpreted then you will need something higher-level (source level) that hooks into the interpreter.

如果您的脚本语言被解释,那么您将需要一些挂钩到解释器的更高级别(源级别)。

#2


3  

Thxm, Mc! http://asm.objectweb.org/ is another one. Excellent documentation on byte code instrumentation, but nothing "directly" aimed at writing a coverage tool - just some hints or ideas.

嗯,麦克! http://asm.objectweb.org/是另一个。有关字节代码检测的优秀文档,但没有“直接”旨在编写覆盖工具 - 只是一些提示或想法。

#3


2  

You can also get the source from a Open Source code coverage tool and learn from it.

您还可以从开源代码覆盖工具中获取源代码并从中学习。

#4


2  

You might also want to use something like BCEL to analyse which lines of source actually exist in the byte-code. You don't want to report that things like blank lines and comments haven't been covered.

您可能还想使用类似BCEL的东西来分析字节代码中实际存在哪些源代码行。您不希望报告尚未涵盖空白行和注释等内容。

#5


2  

If you're talking about ColdFusion (which I assume you are from the tags) then I'm not sure this is doable but I may be very wrong here...

如果你在谈论ColdFusion(我假设你来自标签)那么我不确定这是否可行,但我可能在这里错了...

IIRC, When CF compiles it essentially compiles into a interpreted form of the CFML as a plain old java source file, this is then compiled into the class. Therefore, any instrumentation that you may have will apply to the intermediary version rather than the CFML itself.

IIRC,当CF编译时,它基本上编译成CFML的解释形式,作为普通的旧java源文件,然后将其编译到类中。因此,您可能拥有的任何工具都将应用于中间版本而不是CFML本身。

Saying that though, Adobe have got the CF debugger now which can step though code, so please prove me wrong - I'd love code coverage in CFML.

尽管如此,Adobe现在已经获得了CF调试器,它可以逐步执行代码,所以请证明我错了 - 我喜欢CFML中的代码覆盖。