Skip to content
Skip to breadcrumbs
Skip to header menu
Skip to action menu
Skip to quick search
Quick Search
Browse
Pages
Blog
Labels
Attachments
Mail
Advanced
What’s New
Space Directory
Feed Builder
Keyboard Shortcuts
Confluence Gadgets
Log In
Sign Up
Dashboard
Groovy
Copy Page
You are not logged in. Any changes you make will be marked as
anonymous
. You may want to
Log In
if you already have an account. You can also
Sign Up
for a new account.
This page is being edited by
.
Paragraph
Paragraph
Heading 1
Heading 2
Heading 3
Heading 4
Heading 5
Heading 6
Preformatted
Quote
Bold
Italic
Underline
More colours
Strikethrough
Subscript
Superscript
Monospace
Clear Formatting
Bullet list
Numbered list
Outdent
Indent
Align left
Align center
Align right
Link
Table
Insert
Insert Content
Image
Link
Attachment
Symbol
Emoticon
Wiki Markup
Horizontal rule
tinymce.confluence.insert_menu.macro_desc
Info
JIRA Issue
Status
Gallery
Tasklist
Table of Contents
Other Macros
Page Layout
No Layout
Two column (simple)
Two column (simple, left sidebar)
Two column (simple, right sidebar)
Three column (simple)
Two column
Two column (left sidebar)
Two column (right sidebar)
Three column
Three column (left and right sidebars)
Undo
Redo
Find/Replace
Keyboard Shortcuts Help
<p>Code coverage <table class="wysiwyg-macro" data-macro-name="excerpt" data-macro-parameters="atlassian-macro-output-type=INLINE" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e2V4Y2VycHQ6YXRsYXNzaWFuLW1hY3JvLW91dHB1dC10eXBlPUlOTElORX0&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="RICH_TEXT"><tr><td class="wysiwyg-macro-body"><p>is a useful measure of the effectiveness of unit tests and can be derived for Groovy tests</p></td></tr></table>.</p> <p>Consider the following Groovy code:</p> <table class="wysiwyg-macro" data-macro-name="code" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e2NvZGV9&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre> class BiggestPairCalc { int sumBiggestPair(int a, int b, int c) { def op1 = a def op2 = b if (c > a) { op1 = c } else if (c > b) { op2 = c } return op1 + op2 } } </pre></td></tr></table> <p>And the following test:</p> <table class="wysiwyg-macro" data-macro-name="code" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e2NvZGV9&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre> class BiggestPairCalcTest extends GroovyTestCase { void testSumBiggestPair() { def calc = new BiggestPairCalc() assertEquals(9, calc.sumBiggestPair(5, 4, 1)) } } </pre></td></tr></table> <p>If you use <a href="http://cobertura.sourceforge.net/">Cobertura</a> to perform your coverage, the resulting report might look like:</p> <p><img class="confluence-embedded-image" src="/download/attachments/231080163/cobertura.jpg?version=1&modificationDate=1369412707526" data-image-src="/download/attachments/231080163/cobertura.jpg?version=1&modificationDate=1369412707526" data-linked-resource-id="231375763" data-linked-resource-type="attachment" data-linked-resource-default-alias="cobertura.jpg" data-base-url="http://docs.codehaus.org" data-linked-resource-container-id="231080163" title="null > cobertura.jpg"></p> <p>Your <a href="http://ant.apache.org">Ant</a> build file to make all this happen might look like:</p> <table class="wysiwyg-macro" data-macro-name="code" data-macro-default-parameter="xml" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e2NvZGU6eG1sfQ&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre> <?xml version="1.0"?> <project name="sample" default="coverage-report" basedir="."> <!-- set up properties, paths, taskdefs, prepare targets --> [details deleted] <!-- compile java (if you have any) and groovy source --> <target name="compile" depends="prepare"> <javac srcdir="${dir.src}" destdir="${dir.build}" debug="true"> <classpath refid="project.classpath"/> </javac> <groovyc srcdir="${dir.src}" destdir="${dir.build}" stacktrace="true"> <classpath refid="project.classpath"/> </groovyc> </target> <!-- instrument already compiled class files --> <target name="instrument" depends="compile" > <cobertura-instrument todir="target/instrumented-classes"> <fileset dir="${dir.build}"> <include name="**/*.class"/> </fileset> </cobertura-instrument> </target> <!-- run all junit tests using the instrumented classes --> <target name="cover-test" depends="instrument"> <mkdir dir="${dir.report}/cobertura" /> <junit printsummary="yes" haltonerror="no" haltonfailure="no" fork="yes"> <formatter type="plain" usefile="false"/> <batchtest> <fileset dir="target/instrumented-classes" includes="**/*Test.class" /> </batchtest> <classpath refid="cover-test.classpath"/> </junit> </target> <!-- create the html reports --> <target name="coverage-report" depends="cover-test"> <cobertura-report srcdir="${dir.src}" destdir="${dir.report}/cobertura"/> </target> </project> </pre></td></tr></table> <p>For more details, see <a href="http://groovy.canoo.com/gina">GINA</a> or the <a href="http://cobertura.sourceforge.net/">Cobertura</a> web site or <a class="confluence-link" href="/display/GROOVY/Code+Coverage+with+Cobertura" data-linked-resource-id="49930" data-linked-resource-type="page" data-linked-resource-default-alias="Code Coverage with Cobertura" data-base-url="http://docs.codehaus.org">Code Coverage with Cobertura</a>.</p>
Please type the word appearing in the picture.
Attachments
Labels
Location
Watch this page
< Edit
Preview >
Loading…
Save
Cancel
Next hint
search
attachments
weblink
advanced