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
| 42348 views |
  • submit to reddit

In order to actually start using easyb, you need to download the libraries from here.

Next, create a folder called stories where you will be placing all your easyb stories as shown below:


 

The stories in easyb should and must be in a file ending with an extension of .story. So our login story would be placed in a file called LoginServiceTest.story.

If you have a story named  AccountServiceTest.groovy, you will get an exception as such:

Buildfile: /Users/meerasubbarao/Development/easyb-samples/build.xml
init:
run.easyb.stores:
    [easyb] easyb is preparing to process 2 file(s)
    [easyb] Easyb behavior file must end in Story.groovy, .story, Specification.groovy or .specification. See easyb documentation for more details.
    [easyb] easyb execution FAILED
BUILD SUCCESSFUL
Total time: 1 second

In the above case, as the stack trace reflects, the story should end with 'Story.groovy', and so here, AccountServiceTest.groovy should be AccountServiceTestStory.groovy.

Lets write the scenario for 1 above: User enters valid credentials

scenario "User enters valid credentials", {
given "user account already exists",{

}
when "user logins",{
}
then "the system should return a valid account",{

}
}

In the scenario above, we have a given, when and then. That’s pretty easy, don’t you think? Anyone in the team can write those scenarios. My next step is to implement the next two scenarios.

scenario "User enters invalid credentials", {
given "user account already exists",{

}
when "user logins with invalid password",{
}
then "a null account should be returned",{

}
}

and the last one:

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 above scenarios are just bare bones, lets add some actual code and try to run them.

As I mentioned earlier, I have a simple mock implementations for the AccountService and LoginService.

The three scenarios with valid code would look like:

scenario "User enters valid credentials", {
given "user account already exists",{
accountService = new AccountServiceImpl()
loginService = new LoginServiceImpl()
loginService.setAccountService(accountService)

}
when "user logins",{
account = loginService.login("meera", "password")
}
then "the system returns a valid account",{
account.getUserid().shouldBe "meera"
account.getPassword().shouldBe "password"

}
}

scenario "User enters invalid credentials", {
given "user account already exists",{
accountService = new AccountServiceImpl()
loginService = new LoginServiceImpl()
loginService.setAccountService(accountService)
}
when "user logins with invalid password",{
account = loginService.login("meera", "meera")
}
then "a null account should be returned",{
account.shouldBe null
}
}


scenario "Invalid login with a null password", {
given "user account already exists",{
accountService = new AccountServiceImpl()
loginService = new LoginServiceImpl()
loginService.setAccountService(accountService)
}

when "user logins with null password", {
enternull = {
loginService.login("meera", null)
}
}

then "an exception should be thrown", {
ensureThrows(BusinessException.class){
enternull()
}
}

}

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.