{"id":420,"date":"2006-03-30T17:12:21","date_gmt":"2006-03-30T16:12:21","guid":{"rendered":"http:\/\/thekua.com\/rant\/?p=420"},"modified":"2006-03-31T09:46:06","modified_gmt":"2006-03-31T08:46:06","slug":"ask-emma-if-you-are-covered","status":"publish","type":"post","link":"https:\/\/thekua.com\/rant\/2006\/03\/ask-emma-if-you-are-covered\/","title":{"rendered":"Ask EMMA If You Are Covered"},"content":{"rendered":"<p>Code coverage is a useful tool for helping you work out how well you are testing your code. On most projects I have been on, I have found Clover to be the most well known and most popular but there are other alternatives, and this one in particular I am going to demonstrate how to use it.<\/p>\n<p>On our current project, I used <a href=\"http:\/\/emma.sourceforge.net\/\">EMMA<\/a>, an open source code coverage tool, to monitor how well we were testing various aspects of the code base. Results highlighted areas that were not test driven or areas that the team had neglected to deal with at the time (such as certain exception handling). This library is not specifically design to work only with JUnit, so I thought it might be useful to show you how we use it in our normal build that does use JUnit. <\/p>\n<p><strong>Steps to generate code coverage using EMMA<\/strong><\/p>\n<ol>\n<li>Compile your classes<\/li>\n<li>Instrument your classes<\/li>\n<li>Execute your tests<\/li>\n<li>Generate the report<\/li>\n<\/ol>\n<p><strong>Compile Your Classes<\/strong><br \/>\nWith EMMA there is no change to the way that you can compile your classes as it allows you to instrument them post-compilation.<\/p>\n<p><strong>Instrument Your Classes<\/strong><br \/>\nThe distribution comes with a class that you can run against a set of classes that automatically generates the instrumented classes as shown below:<\/p>\n<blockquote><p><code>java \u00e2\u20ac\u201ccp emma.jar emma instr \u00e2\u20ac\u201cm overwrite \u00e2\u20ac\u201ccp build\/classes<\/code><\/p><\/blockquote>\n<p>where:<br \/>\n[<code>emma<\/code>] Is the executable java class for easily running all the features from this library.<br \/>\n[<code>instr<\/code>] Is the command for executing the instrumentation that weaves in all the monitoring features for generate code coverage information.<br \/>\n[<code>-m overwrite<\/code>] Is the output mode and states to overwrite the original classes. You can also output a copy if you want but you will have to specify the output directory using the \u00e2\u20ac\u201cd\/-dir\/-outputdir option<br \/>\n[<code>-cp build\/classes<\/code>] tells EMMA where it should be looking for the files to instrument.<\/p>\n<p><strong>Execute Your Tests<\/strong><br \/>\nAfter instrumenting your classes with the features that monitor code coverage, you only need to run your tests as normal, only ensuring that you include the EMMA&#8217;s library jar in the classpath.<\/p>\n<p>After running your tests you will see two output files including <code>coverage.em<\/code> and <code>coverage.ec<\/code> that are both used as inputs into the report.<\/p>\n<p><strong>Generate The Report<\/strong><br \/>\nWe will reuse the same executable class for generating the report as below:<\/p>\n<blockquote><p><code>java \u00e2\u20ac\u201ccp emma.jar emma report \u00e2\u20ac\u201cr html \u00e2\u20ac\u201cin ..\/coverage.em,..\/coverage.ec -sp ..\/src<\/code><\/p><\/blockquote>\n<p>where:<br \/>\n[<code>emma<\/code>] Is the executable java class for easily running all the features from this library.<br \/>\n[<code>report<\/code>] tells emma that you want to generate a report from the coverage readings<br \/>\n[<code>-r html<\/code>] tells what format the report should be in<br \/>\n[<code>\u00e2\u20ac\u201cin ..\/coverage.em,..\/coverage.ec<\/code>] tells emma where to find the code coverage data<br \/>\n[<code>-sp ..\/src<\/code>] links the java source files to the results so that you can get some nice graphical reports.<\/p>\n<p>Your should end up with a HTML report that outputs something like the following:<\/p>\n<div style=\"text-align:center\">\n<a href=\"http:\/\/thekua.com\/rant\/wp-content\/uploads\/2006\/03\/EmmaSummaryReport.gif\"><img decoding=\"async\" id=\"image419\" src=\"http:\/\/thekua.com\/rant\/wp-content\/uploads\/2006\/03\/EmmaSummaryReportSmall.gif\" alt=\"Summary Code Coverage Report\"\/><\/a><br \/>\nSummary Report<br \/>\n<a href=\"http:\/\/thekua.com\/rant\/wp-content\/uploads\/2006\/03\/EmmaReportWithSource.png\"><img decoding=\"async\" id=\"image418\" src=\"http:\/\/thekua.com\/rant\/wp-content\/uploads\/2006\/03\/EmmaReportWithSourceSmall.gif\" alt=\"Code Coverage Report with Source\" \/><\/a><br \/>\nAn example output file with source attached\n<\/div>\n<p><strong>Ant Build Integration<\/strong><br \/>\nYou can use <a href=\"http:\/\/thekua.com\/rant\/wp-content\/emma.xml\">this build file<\/a> (substituting appropriate values) if you want to get up and running quickly. It assumes:<\/p>\n<ul>\n<li>You have the appropriate emma jar in the specified location (see buildfile)<\/li>\n<li>You have the jar in the classpath of the tests<\/li>\n<li>You have <strong>compile<\/strong> and <strong>test<\/strong> targets<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Code coverage is a useful tool for helping you work out how well you are testing your code. On most projects I have been on, I have found Clover to be the most well known and most popular but there are other alternatives, and this one in particular I am going to demonstrate how to [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[39],"class_list":["post-420","post","type-post","status-publish","format-standard","hentry","category-technical","tag-work-related"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.8 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Ask EMMA If You Are Covered - thekua.com@rest<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/thekua.com\/rant\/2006\/03\/ask-emma-if-you-are-covered\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Ask EMMA If You Are Covered - thekua.com@rest\" \/>\n<meta property=\"og:description\" content=\"Code coverage is a useful tool for helping you work out how well you are testing your code. On most projects I have been on, I have found Clover to be the most well known and most popular but there are other alternatives, and this one in particular I am going to demonstrate how to [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/thekua.com\/rant\/2006\/03\/ask-emma-if-you-are-covered\/\" \/>\n<meta property=\"og:site_name\" content=\"thekua.com@rest\" \/>\n<meta property=\"article:published_time\" content=\"2006-03-30T16:12:21+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2006-03-31T08:46:06+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/thekua.com\/rant\/wp-content\/uploads\/2006\/03\/EmmaSummaryReportSmall.gif\" \/>\n<meta name=\"author\" content=\"Patrick\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Patrick\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/thekua.com\\\/rant\\\/2006\\\/03\\\/ask-emma-if-you-are-covered\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/thekua.com\\\/rant\\\/2006\\\/03\\\/ask-emma-if-you-are-covered\\\/\"},\"author\":{\"name\":\"Patrick\",\"@id\":\"https:\\\/\\\/thekua.com\\\/rant\\\/#\\\/schema\\\/person\\\/6de103b28f96be3f1f4dc25db357c6ae\"},\"headline\":\"Ask EMMA If You Are Covered\",\"datePublished\":\"2006-03-30T16:12:21+00:00\",\"dateModified\":\"2006-03-31T08:46:06+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/thekua.com\\\/rant\\\/2006\\\/03\\\/ask-emma-if-you-are-covered\\\/\"},\"wordCount\":510,\"commentCount\":2,\"publisher\":{\"@id\":\"https:\\\/\\\/thekua.com\\\/rant\\\/#\\\/schema\\\/person\\\/6de103b28f96be3f1f4dc25db357c6ae\"},\"image\":{\"@id\":\"https:\\\/\\\/thekua.com\\\/rant\\\/2006\\\/03\\\/ask-emma-if-you-are-covered\\\/#primaryimage\"},\"thumbnailUrl\":\"http:\\\/\\\/thekua.com\\\/rant\\\/wp-content\\\/uploads\\\/2006\\\/03\\\/EmmaSummaryReportSmall.gif\",\"keywords\":[\"Work-Related\"],\"articleSection\":[\"Work Related\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/thekua.com\\\/rant\\\/2006\\\/03\\\/ask-emma-if-you-are-covered\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/thekua.com\\\/rant\\\/2006\\\/03\\\/ask-emma-if-you-are-covered\\\/\",\"url\":\"https:\\\/\\\/thekua.com\\\/rant\\\/2006\\\/03\\\/ask-emma-if-you-are-covered\\\/\",\"name\":\"Ask EMMA If You Are Covered - thekua.com@rest\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/thekua.com\\\/rant\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/thekua.com\\\/rant\\\/2006\\\/03\\\/ask-emma-if-you-are-covered\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/thekua.com\\\/rant\\\/2006\\\/03\\\/ask-emma-if-you-are-covered\\\/#primaryimage\"},\"thumbnailUrl\":\"http:\\\/\\\/thekua.com\\\/rant\\\/wp-content\\\/uploads\\\/2006\\\/03\\\/EmmaSummaryReportSmall.gif\",\"datePublished\":\"2006-03-30T16:12:21+00:00\",\"dateModified\":\"2006-03-31T08:46:06+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/thekua.com\\\/rant\\\/2006\\\/03\\\/ask-emma-if-you-are-covered\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/thekua.com\\\/rant\\\/2006\\\/03\\\/ask-emma-if-you-are-covered\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/thekua.com\\\/rant\\\/2006\\\/03\\\/ask-emma-if-you-are-covered\\\/#primaryimage\",\"url\":\"http:\\\/\\\/thekua.com\\\/rant\\\/wp-content\\\/uploads\\\/2006\\\/03\\\/EmmaSummaryReportSmall.gif\",\"contentUrl\":\"http:\\\/\\\/thekua.com\\\/rant\\\/wp-content\\\/uploads\\\/2006\\\/03\\\/EmmaSummaryReportSmall.gif\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/thekua.com\\\/rant\\\/2006\\\/03\\\/ask-emma-if-you-are-covered\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/thekua.com\\\/rant\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Ask EMMA If You Are Covered\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/thekua.com\\\/rant\\\/#website\",\"url\":\"https:\\\/\\\/thekua.com\\\/rant\\\/\",\"name\":\"thekua.com@rest\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\\\/\\\/thekua.com\\\/rant\\\/#\\\/schema\\\/person\\\/6de103b28f96be3f1f4dc25db357c6ae\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/thekua.com\\\/rant\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/thekua.com\\\/rant\\\/#\\\/schema\\\/person\\\/6de103b28f96be3f1f4dc25db357c6ae\",\"name\":\"Patrick\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/thekua.com\\\/rant\\\/wp-content\\\/uploads\\\/2025\\\/12\\\/pat-kua-head.png\",\"url\":\"https:\\\/\\\/thekua.com\\\/rant\\\/wp-content\\\/uploads\\\/2025\\\/12\\\/pat-kua-head.png\",\"contentUrl\":\"https:\\\/\\\/thekua.com\\\/rant\\\/wp-content\\\/uploads\\\/2025\\\/12\\\/pat-kua-head.png\",\"width\":400,\"height\":400,\"caption\":\"Patrick\"},\"logo\":{\"@id\":\"https:\\\/\\\/thekua.com\\\/rant\\\/wp-content\\\/uploads\\\/2025\\\/12\\\/pat-kua-head.png\"},\"sameAs\":[\"http:\\\/\\\/www.thekua.com\"],\"url\":\"https:\\\/\\\/thekua.com\\\/rant\\\/author\\\/patrick\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Ask EMMA If You Are Covered - thekua.com@rest","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/thekua.com\/rant\/2006\/03\/ask-emma-if-you-are-covered\/","og_locale":"en_US","og_type":"article","og_title":"Ask EMMA If You Are Covered - thekua.com@rest","og_description":"Code coverage is a useful tool for helping you work out how well you are testing your code. On most projects I have been on, I have found Clover to be the most well known and most popular but there are other alternatives, and this one in particular I am going to demonstrate how to [&hellip;]","og_url":"https:\/\/thekua.com\/rant\/2006\/03\/ask-emma-if-you-are-covered\/","og_site_name":"thekua.com@rest","article_published_time":"2006-03-30T16:12:21+00:00","article_modified_time":"2006-03-31T08:46:06+00:00","og_image":[{"url":"http:\/\/thekua.com\/rant\/wp-content\/uploads\/2006\/03\/EmmaSummaryReportSmall.gif","type":"","width":"","height":""}],"author":"Patrick","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Patrick","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/thekua.com\/rant\/2006\/03\/ask-emma-if-you-are-covered\/#article","isPartOf":{"@id":"https:\/\/thekua.com\/rant\/2006\/03\/ask-emma-if-you-are-covered\/"},"author":{"name":"Patrick","@id":"https:\/\/thekua.com\/rant\/#\/schema\/person\/6de103b28f96be3f1f4dc25db357c6ae"},"headline":"Ask EMMA If You Are Covered","datePublished":"2006-03-30T16:12:21+00:00","dateModified":"2006-03-31T08:46:06+00:00","mainEntityOfPage":{"@id":"https:\/\/thekua.com\/rant\/2006\/03\/ask-emma-if-you-are-covered\/"},"wordCount":510,"commentCount":2,"publisher":{"@id":"https:\/\/thekua.com\/rant\/#\/schema\/person\/6de103b28f96be3f1f4dc25db357c6ae"},"image":{"@id":"https:\/\/thekua.com\/rant\/2006\/03\/ask-emma-if-you-are-covered\/#primaryimage"},"thumbnailUrl":"http:\/\/thekua.com\/rant\/wp-content\/uploads\/2006\/03\/EmmaSummaryReportSmall.gif","keywords":["Work-Related"],"articleSection":["Work Related"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/thekua.com\/rant\/2006\/03\/ask-emma-if-you-are-covered\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/thekua.com\/rant\/2006\/03\/ask-emma-if-you-are-covered\/","url":"https:\/\/thekua.com\/rant\/2006\/03\/ask-emma-if-you-are-covered\/","name":"Ask EMMA If You Are Covered - thekua.com@rest","isPartOf":{"@id":"https:\/\/thekua.com\/rant\/#website"},"primaryImageOfPage":{"@id":"https:\/\/thekua.com\/rant\/2006\/03\/ask-emma-if-you-are-covered\/#primaryimage"},"image":{"@id":"https:\/\/thekua.com\/rant\/2006\/03\/ask-emma-if-you-are-covered\/#primaryimage"},"thumbnailUrl":"http:\/\/thekua.com\/rant\/wp-content\/uploads\/2006\/03\/EmmaSummaryReportSmall.gif","datePublished":"2006-03-30T16:12:21+00:00","dateModified":"2006-03-31T08:46:06+00:00","breadcrumb":{"@id":"https:\/\/thekua.com\/rant\/2006\/03\/ask-emma-if-you-are-covered\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/thekua.com\/rant\/2006\/03\/ask-emma-if-you-are-covered\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/thekua.com\/rant\/2006\/03\/ask-emma-if-you-are-covered\/#primaryimage","url":"http:\/\/thekua.com\/rant\/wp-content\/uploads\/2006\/03\/EmmaSummaryReportSmall.gif","contentUrl":"http:\/\/thekua.com\/rant\/wp-content\/uploads\/2006\/03\/EmmaSummaryReportSmall.gif"},{"@type":"BreadcrumbList","@id":"https:\/\/thekua.com\/rant\/2006\/03\/ask-emma-if-you-are-covered\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/thekua.com\/rant\/"},{"@type":"ListItem","position":2,"name":"Ask EMMA If You Are Covered"}]},{"@type":"WebSite","@id":"https:\/\/thekua.com\/rant\/#website","url":"https:\/\/thekua.com\/rant\/","name":"thekua.com@rest","description":"","publisher":{"@id":"https:\/\/thekua.com\/rant\/#\/schema\/person\/6de103b28f96be3f1f4dc25db357c6ae"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/thekua.com\/rant\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/thekua.com\/rant\/#\/schema\/person\/6de103b28f96be3f1f4dc25db357c6ae","name":"Patrick","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/thekua.com\/rant\/wp-content\/uploads\/2025\/12\/pat-kua-head.png","url":"https:\/\/thekua.com\/rant\/wp-content\/uploads\/2025\/12\/pat-kua-head.png","contentUrl":"https:\/\/thekua.com\/rant\/wp-content\/uploads\/2025\/12\/pat-kua-head.png","width":400,"height":400,"caption":"Patrick"},"logo":{"@id":"https:\/\/thekua.com\/rant\/wp-content\/uploads\/2025\/12\/pat-kua-head.png"},"sameAs":["http:\/\/www.thekua.com"],"url":"https:\/\/thekua.com\/rant\/author\/patrick\/"}]}},"_links":{"self":[{"href":"https:\/\/thekua.com\/rant\/wp-json\/wp\/v2\/posts\/420","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/thekua.com\/rant\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/thekua.com\/rant\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/thekua.com\/rant\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/thekua.com\/rant\/wp-json\/wp\/v2\/comments?post=420"}],"version-history":[{"count":0,"href":"https:\/\/thekua.com\/rant\/wp-json\/wp\/v2\/posts\/420\/revisions"}],"wp:attachment":[{"href":"https:\/\/thekua.com\/rant\/wp-json\/wp\/v2\/media?parent=420"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/thekua.com\/rant\/wp-json\/wp\/v2\/categories?post=420"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/thekua.com\/rant\/wp-json\/wp\/v2\/tags?post=420"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}