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

<p>This is for a scripting language that generates Java byte code under the hood.</p>

[{'answer_id': 2216, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 2, 'selected': False, 'text': '<p>Thxm, Mc! <a href="http://asm.objectweb.org" rel="nofollow noreferrer">http://asm.objectweb.org</a>/ is another one. <em>Excellent</em> documentation on byte code instrumentation, but nothing "directly" aimed at writing a coverage tool - just some hints or ideas.</p>\n'}, {'answer_id': 7076, 'author': 'Dominic Cooney', 'author_id': 878, 'author_profile': 'https://Stackoverflow.com/users/878', 'pm_score': 3, 'selected': False, 'text': '<p>Does your scripting language generate bytecode? Does it generate debug metadata? If so, bytecode instrumentation is probably the way to go. In fact existing tools will probably work (perhaps with minimal modification).</p>\n\n<p>The typical problem with such tools that they are written to work with Java and assume that a <code>class com.foo.Bar.class</code> corresponds to a file <code>com/foo/Bar.java</code>. Unwinding that assumption can be tedious.</p>\n\n<p><a href="http://emma.sourceforge.net/" rel="nofollow noreferrer">EMMA</a> 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 source code for some ideas.</p>\n\n<p>If your scripting language is interpreted then you will need a higher-level class loader (at a source level) that hooks into the interpreter.</p>\n'}, {'answer_id': 9086, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 2, 'selected': False, 'text': '<p>You can also get the source from a Open Source code coverage tool and learn from it.</p>\n'}, {'answer_id': 65482, 'author': 'djpowell', 'author_id': 7274, 'author_profile': 'https://Stackoverflow.com/users/7274', 'pm_score': 2, 'selected': False, 'text': "<p>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.</p>\n"}, {'answer_id': 267182, 'author': 'Neil Middleton', 'author_id': 4787, 'author_profile': 'https://Stackoverflow.com/users/4787', 'pm_score': 2, 'selected': False, 'text': "<p>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...</p>\n\n<p>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.</p>\n\n<p>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.</p>\n"}]
['https://Stackoverflow.com/questions/2092', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/-1/']