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://jbehave.org/">JBehave</a> is a Behaviour Driven Development (<a href="http://en.wikipedia.org/wiki/Behavior_driven_development">BDD</a>) framework for Java.</p> <p>The sections below illustrate using JBehave for the examples from <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 Stack Example</h2> <p>Here is how you might use JBehave to test the <a class="confluence-link" href="/display/GROOVY/Using+Testing+Frameworks+with+Groovy#UsingTestingFrameworkswithGroovy-AStackExample" data-anchor="AStackExample" data-linked-resource-id="67695" data-linked-resource-type="page" data-linked-resource-default-alias="Using Testing Frameworks with Groovy#AStackExample" data-base-url="http://docs.codehaus.org">Stack Example</a>:</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(url:'http://jbehave.org/', jar='jbehave-1.0.1.jar') import org.jbehave.core.Run import org.jbehave.core.behaviour.Behaviours class AlmostEmptyFixedStackBehavior { private stack void setUp() { stack = new FixedStack() stack.push 'anything' assert !stack.isEmpty() } void shouldRemainNotEmptyAfterPeek() { stack.peek() assert !stack.isEmpty() } void shouldBecomeEmptyAfterPop() { stack.pop() assert stack.isEmpty() } } class AlmostFullFixedStackBehavior { private stack void setUp() { stack = new FixedStack() (1..<FixedStack.MAXSIZE).each{ x -> stack.push x } assert !stack.isFull() } void shouldBecomeFullAfterPush() { stack.push 'anything' assert stack.isFull() } } class EmptyFixedStackBehavior extends GroovyTestCase { private stack = new FixedStack() void shouldInitiallyBeEmpty() { assert stack.isEmpty() } void shouldNoLongerBeEmptyAfterPush() { stack.push 'anything' assert !stack.isEmpty() } void shouldComplainWhenSentPeek() { shouldFail(StackUnderflowException) { stack.peek() } } void shouldComplainWhenSentPop() { shouldFail(StackUnderflowException) { stack.pop() } } } class FullFixedStackBehavior extends GroovyTestCase { private stack void setUp() { stack = new FixedStack() (1..FixedStack.MAXSIZE).each{ x -> stack.push x } assert stack.isFull() } void shouldRemainFullAfterPeek() { stack.peek() assert stack.isFull() } void shouldNoLongerBeFullAfterPop() { stack.pop() assert !stack.isFull() } void shouldComplainOnPush() { shouldFail(StackOverflowException) { stack.push 'anything' } } } class NonEmptyFixedStackBehavior { private stack void setUp() { stack = new FixedStack() ('a'..'c').each{ x -> stack.push x } assert !stack.isEmpty() } void shouldAddToTheTopWhenSentPush() { stack.push 'd' assert stack.peek() == 'd' } void shouldBeUnchangedWhenSentPushThenPop() { stack.push 'anything' stack.pop() assert stack.peek() == 'c' } void shouldReturnTheTopItemWhenSentPeek() { assert stack.peek() == 'c' } void shouldNotRemoveTheTopItemWhenSentPeek() { assert stack.peek() == 'c' assert stack.peek() == 'c' } void shouldReturnTheTopItemWhenSentPop() { assert stack.pop() == 'c' } void shouldRemoveTheTopItemWhenSentPop() { assert stack.pop() == 'c' assert stack.pop() == 'b' } } class AllBehaviours implements Behaviours { Class[] getBehaviours() { return [ AlmostEmptyFixedStackBehavior, AlmostFullFixedStackBehavior, EmptyFixedStackBehavior, FullFixedStackBehavior, NonEmptyFixedStackBehavior ] } } Run.main('AllBehaviours') </pre></td></tr></table> <h2>The Item Storer Example</h2> <p>Here is how you might use JBehave to test 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> <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(url:'http://jbehave.org/', jar='jbehave-1.0.1.jar') import org.jbehave.core.Run class JBehaveStorerBehavior { def storer = new Storer() def static checkPersistAndReverse(cut, value, reverseValue) { cut.put(value) assert value == cut.get() assert reverseValue == cut.getReverse() } void shouldReverseStrings() { checkPersistAndReverse storer, 'hello', 'olleh' } void shouldReverseNumbers() { checkPersistAndReverse storer, 123.456, -123.456 } void shouldReverseLists() { checkPersistAndReverse storer, [1, 3, 5], [5, 3, 1] } } Run.main('JBehaveStorerBehavior') </pre></td></tr></table>
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