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><a href="http://jdummy.sourceforge.net/">JDummy</a> is a thin API which sits above JMock. It allows very succinct expectation setting code when the expectation code would normally involve many stubs.</p> <p>The sections below illustrate using JDummy for the mocking parts of <a class="confluence-link" href="/display/GROOVY/Using+Testing+Frameworks+with+Groovy" data-linked-resource-id="67695" data-linked-resource-type="page" data-linked-resource-default-alias="Using Testing Frameworks with Groovy" data-base-url="http://docs.codehaus.org">Using Testing Frameworks with Groovy</a>.</p> <h2>The Item Storer Example</h2> <p>We are going to consider how you might use JDummy as part of testing the <a class="confluence-link" href="/display/GROOVY/Using+Testing+Frameworks+with+Groovy#UsingTestingFrameworkswithGroovy-AnItemStorerExample" data-anchor="AnItemStorerExample" data-linked-resource-id="67695" data-linked-resource-type="page" data-linked-resource-default-alias="Using Testing Frameworks with Groovy#AnItemStorerExample" data-base-url="http://docs.codehaus.org">Item Storer Example</a>.</p> <p>Here is how we can test <code>JavaStorer</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> // require(groupId:'jmock', artifactId:'jmock', version='1.2.0') // require(groupId:'jmock', artifactId:'jmock-cglib', version='1.2.0') // require(groupId:'junit', artifactId:'junit', version='3.8.2') // require(groupId:'cglib', artifactId:'cglib-nodep', version='2.2_beta1') // require(url:'jdummy.sf.net', jar:'jdummy-1.3.3.jar') import net.sf.jdummy.JDummyTestCase class JDummyTest extends JDummyTestCase { def mockReverser, storer protected void setUp() throws Exception { mockReverser = mimicWithDummyValues(Reverser.class) storer = new JavaStorer(mockReverser) } void testStorage() { expectReverse(123.456, -123.456) expectReverse('hello', 'olleh') checkReverse(123.456, -123.456) checkReverse('hello', 'olleh') } def expectReverse(input, output) { // with is a keyword in Groovy so we quote it assertBehavior(mockReverser).expects(once()).method('reverse').'with'(eq(input)).will(returnValue(output)) } def checkReverse(value, reverseValue) { storer.put(value) assert value == storer.get() assert reverseValue == storer.getReverse() } } def suite = new junit.framework.TestSuite() suite.addTestSuite(JDummyTest.class) junit.textui.TestRunner.run(suite) </pre></td></tr></table> <p>Note: Our example is so simple, that JDummy's power is not really illustrated here.</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