Agile Zone is brought to you in partnership with:

Meera has posted 70 posts at DZone. You can read more from them at their website. View Full User Profile

Is easyb Easy?

09.17.2008
| 41168 views |
  • submit to reddit

Once you have the story written, we need to run these. easyb can be invoked via:

    * the command line
    * Ant
    * Maven
    * IntelliJ

I am a big fan of automation, so I chose the easy way;Ant.

It’s quite easy to run easyb from Ant. Here is what you need to do:

1. Define a task:

<taskdef name="easyb" classname="org.disco.easyb.ant.BehaviorRunnerTask">
<classpath>
<path refid="easyb.classpath" />
</classpath>
</taskdef>

 2. Run the task:

<easyb>
<classpath>
<path refid="easyb.classpath" />
<pathelement path="${test.classes.dir}" />
<pathelement path="${build.classes.dir}" />
</classpath>
<report location="build/story.txt" format="txtstory" />
<behaviors dir="stories">
</behaviors>
</easyb>

3. Verify the output:

Buildfile: /Users/meerasubbarao/Development/easyb-samples/build.xml
init:
run.easyb.stores:
[easyb] easyb is preparing to process 1 file(s)
[easyb] Running login service test story (LoginServiceTest.story)
[easyb] Scenarios run: 3, Failures: 0, Pending: 0, Time Elapsed: 0.486 sec
[easyb] 3 total behaviors run with no failures
[easyb] easyb execution passed
BUILD SUCCESSFUL
Total time: 1 second

 

4. Story Printing:

In the Ant task in 2, we created a report element with its format attribute set to txtstory as follows:

<report location="build/story.txt" format="txtstory" />

If you open up the story.txt file within the build folder, it conatins a report of the scenarios run as shown below:

3 scenarios (including 0 pending) executed successfully

  Story: login service test

    scenario User enters valid credentials
      given user account already exists
      when user logins
      then the system returns a valid account

    scenario User enters invalid credentials
      given user account already exists
      when user logins with invalid password
      then  a null account should be returned

    scenario Invalid login with a null password
      given user account already exists
      when user logins with null password
      then an exception should be thrown

 

The report above looks like something even a 5th grader could understand, right?

If you want to use easyb from within Maven, or from the Command Line, or even IntelliJ, refer to the easyb web site which has examples for all of them. 

Published at DZone with permission of its author, Meera Subbarao.

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)

Comments

Kode Ninja replied on Wed, 2008/09/17 - 7:02am

Meera, if you use the .groovy extension, then your stories should end in 'Story.groovy', not just '.groovy'.

So, your AccountServiceTest.groovy should actually be named AccountServiceTestStory.groovy

Cheers!

Kodeninja

Meera Subbarao replied on Wed, 2008/09/17 - 7:03am in response to: Kode Ninja

[quote=kodeninja]

So, your AccountServiceTest.groovy should actually be named AccountServiceTestStory.groovy

[/quote]

 Thanks so much, I will correct the post reflecting the same.

Meera Subbarao

Jochen Bedersdorfer replied on Wed, 2008/09/17 - 7:13pm

Would have been interesting to see when a test fails.

Apart from that, thank you for the smooth introduction to easyb

Meera Subbarao replied on Wed, 2008/09/17 - 7:28pm in response to: Jochen Bedersdorfer

[quote=beders]

Would have been interesting to see when a test fails.

 [/quote]

Great, idea. Never thought about the same. I will update the post.

Meera Subbarao

David Sills replied on Thu, 2008/09/18 - 11:04am

Meera:

 What an interesting post! I wonder how much of this can be actually laid out by the user, perhaps sort of Fit style, to enable more effective Acceptance TDD? Just a thought.

David Sills

 

Meera Subbarao replied on Thu, 2008/09/18 - 11:12am in response to: David Sills

[quote=davidsills]

I wonder how much of this can be actually laid out by the user, perhaps sort of Fit style, to enable more effective Acceptance TDD? Just a thought.

[/quote]

I think most of it can be written by the user, the developer just needs to fill in the code. 

Meera Subbarao

Meera Subbarao replied on Thu, 2008/09/18 - 11:19am in response to: Jochen Bedersdorfer

[quote=beders]

Would have been interesting to see when a test fails.

[/quote]

The article has been updated for a failing scenario as well.

Meera Subbarao

Jochen Bedersdorfer replied on Thu, 2008/09/18 - 11:35am in response to: Meera Subbarao

Thank you.

I like the test result. It clearly tells you what was wrong and the description can almost be used directly in a bug tracking system.

Nice

Tushar Joshi replied on Wed, 2008/10/01 - 5:31am

File must end with Story.groovy error 

I tried EasyB in NetBeans and it continuously gave me the error that the file must end with Story.groovy

When searched for similar issue in EasyB Users list I came across the issue of folder having spaces in the names.  My netbeans project is inside NetBeansProject folder which is by default made in the My Documents folder which has a space.  I moved the EasyB project to a folder having no space and it worked.

 Just adding here for people who may face the same problem with Netbeans. 

 

with regards

Tushar 

Meera Subbarao replied on Wed, 2008/10/01 - 8:45am in response to: Tushar Joshi

[quote=tusharvjoshi]

When searched for similar issue in EasyB Users list I came across the issue of folder having spaces in the names.  My netbeans project is inside NetBeansProject folder which is by default made in the My Documents folder which has a space.  I moved the EasyB project to a folder having no space and it worked.

[/quote]

Thanks for sharing, Tushar.

Meera Subbarao

Syed Abu replied on Tue, 2009/04/28 - 10:27am

hey Meera

 Thank for doing a good job. In easyb  i am getting this erxception

 unable to resolve class LoginServiceImpl

 Actually i just copied ur code then slightly changed  and trying to run it.

 and one more thing that i am thinking that the problem is in story fil. The following is my story file code

 scenario "User enters valid credentials", {
 given "user account already exists",{      
       loginService = new LoginServiceImpl()
 }
 when "user logins",{
 account = loginService.login("javasyed", "javasyed")
 }
 then "the system returns a valid account",{
 account.getUserid().shouldBe "javasyed"
 account.getPassword().shouldBe "javasyed"
 }
}

is any problem in referring java classes in stories?

 

Regards,

Syed.

 

 

 

 

 

Ravi Hasija replied on Sat, 2009/11/07 - 11:54am

Hey Meera, Good work Meera! Do you have the project anywhere where it can be downloaded from? Thanks, Ravi

Meera Subbarao replied on Tue, 2009/11/10 - 6:45pm in response to: Ravi Hasija

Ravi,

I don't have the project. Sorry about that.

sridhar chidurala replied on Fri, 2010/03/05 - 11:19pm

Can I use easyb for integration tests? In my project we inject spring beans (including hibernate session factory) into the test case. can i do that with easyb?

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.