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

I was introduced to easyb by none other than the creator of easyb: Andrew Glover. In spite of hearing and reading a lot about easyb from Andy, I never had a chance to actually work on easyb. So, I spent a couple of hours last weekend to dig deep into this framework and to see if easyb was any easy at all.

easyb is a BDD framework for the Java platform. If you have no clue what BDD is, here is a quote from the easyb web site:

Behavior driven development (or BDD) isn't anything new or revolutionary-- it's just an evolutionary offshoot of test driven development, in which the word test is replaced by the word should. Semantics aside, a lot of people have found that the concept of should is a much more natural development driver than the concept of testing. In fact, when you think in terms of behavior (i.e. shoulds) you'll find that writing specifications is easier to do first, which is the intent of test driven development in the first place.

With easyb you express your story and specification using Groovy based domain specific language(DSL). You can use easyb for both Java and Groovy applications.

What is a story? A story can contain any number of scenarios. Each scenario has:

    * Given (a context)
    * When (something happens)
    * Then (something else happens)

I am using a simple login application which was written in both Spring 2.5 and EJB 3.0. In order to test the login functionality, we can write three simple scenarios here:

  • User enters valid credentials.
  • User enters invalid credentials.
  • Invalid login with a null password.


Let me list the Business interfaces and my Domain Class here:
 

1. AccountService

package com.stelligent.easyb.samples.service;

import com.stelligent.easyb.samples.domain.Account;
/**
*
* @author msubbarao
*/

public interface AccountService {

public Account createAccount(Account info);

public Account findAccount(String userid);


}

2. LoginService

package com.stelligent.easyb.samples.service;

import com.stelligent.easyb.samples.domain.Account;
import com.stelligent.easyb.samples.exception.BusinessException;
/**
*
* @author msubbarao
*/

public interface LoginService {

public Account login(String userid, String password) throws BusinessException;

}

3. Account domain class:

package com.stelligent.easyb.samples.domain;

import java.io.Serializable;

/**
*
* @author msubbarao
*/
public class Account implements Serializable {

private String userid;

private String email;

private String firstname;

private String lastname;

private String password;



public Account() {
}

public Account(String userid, String email, String firstname, String lastname, String password) {
this.userid = userid;
this.email = email;
this.firstname = firstname;
this.lastname = lastname;
this.password = password;

}

public String getUserid() {
return userid;
}

public void setUserid(String userid) {
this.userid = userid;
}

......
}

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.