Hey,

I'm in the process of starting a new project for doing GTD on both individual and organizational levels, and was shopping around for test frameworks. Knowing Dan I looked into JBehave, and found it to be absolutely wonderful! I integrated it with Qi4j(.org), which is the app framework we are using, in about an hour, and now feel reasonably comfortable with the process. The integration includes automatically adding the Steps to the UI layer of the app to be tested, so that it can use dependency injection to access the UI and Application layers to perform the actual testing. This is mostly for functional testing rather than unit testing, I should say.

Basically, here's how it could look like (actual code):
public class LoginSteps
        extends Steps
{
   // Injection of app-layer service
   @Service Navigator navigator;

   private String result;
   private Account account;

   @Given("an account")
   public void newAccount() throws AssemblyException
   {
      account = navigator.individual().newAccount();
ValueBuilder<AccountSettingsValue> builder = account.settings().buildWith();
      builder.prototype().server().set("http://localhost:8040";);
      builder.prototype().userName().set("");
      builder.prototype().password().set("");
      builder.prototype().rememberPassword().set(true);
      account.updateSettings(builder.newInstance());
   }

   @When("username is $username and password is $password")
public void loginWith(String username, String password) throws NoSuchMethodException
   {
ValueBuilder<AccountSettingsValue> builder = account.settings().buildWith();
      builder.prototype().userName().set(username);
      builder.prototype().password().set(password);
      account.updateSettings(builder.newInstance());
      try
      {
         navigator.testConnection(account);
         result = "Ok";
      } catch (ConnectionException e)
      {
         result = e.getMessage();
      }
   }

   @Then("login is $res")
   public void loginResult(String res)
   {
      ensureThat(res, equalTo(result));
   }

   @Then("user $can register")
   public void registerUser(final String can) throws Exception
   {
      AccountContext.callWithNoException(account, new Callable<Object>()
      {
         public Object call() throws Exception
         {
            try
            {
               navigator.register(account);
               ensureThat(account.isRegistered());
               ensureThat(can, equalTo("can"));
            } catch (RegistrationException e)
            {
               e.printStackTrace();
               ensureThat(!account.isRegistered());
               ensureThat(can, equalTo("cannot"));
            }
            return null;
         }
      });
   }
}
---
Pretty neat! The key trick is as I said that this code automatically gets registered in the UI layer of the application, so when it is run it will see everything that the UI would see normally.

What I am wondering about now is how to build up a scenario state that is fairly complex in order to test scenarios that require a lot things to have happened. The above does the login. But then I need another for accessing the inbox and creating a task. Then another for marking that task with tags, and yet another for adding attachments to it. All of these scenarios require more and more "Givens", I guess, and the question is how you build up such a complex state? Any advice?

thanks, Rickard

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

   http://xircles.codehaus.org/manage_email


Reply via email to