Skip to content

A Better Way?

Yet another Lunchtime Conversation; this time about easyb and responses to my earlier posting Green is Good, but easyb may be Even Better….

Basically, the question was “What’s wrong with JUnit, anyway!”

Well…

Here is the more ‘traditional’ JUnit-based (but also Groovy-friendly) EasySpec:

package org.easyspec.example

import org.easyspec.*

@EasySpec(interest='A character')
class Character_when_freshly_created_Test extends GroovyTestCase {
    def character

    @Context("that has just been created")
    public void setUp() {
        character = new Character('Thorr')
    }

    @Behavior
    public void test_should_have_a_health_level_of_100() {
        assertEquals 100, character.health
    }

    @Behavior
    public void test_should_have_a_name() {
        assertEquals 'Thorr', character.name
    }
}

(this is the basic EasySpec example, by the way…)

There is also BDoc, which enables ‘goodness’ such as this:

@Test //Scenario
public void givenIHave200$InMyAccountWhenIAskToWithdraw20$ThenIShouldBeGiven20$AndMyBalanceShouldBe180$() {
  Account account = new Account(200);
  int cashGiven = account.withdraw(20);
  assertEquals(20, cashGiven);
  assertEquals(180, account.balance());
}

Now, I do NOT want in any sense to dismiss or belittle these projects, but maybe something more “out of left field” might just be better…compare the EasySpec example above to an equivalent easyb version:

scenario "Freshly Created Characters Test" {
  given "A character that has just been created" {
    character = new Character('Thorr')
  }
  then "The character should have a health level of 100" {
    character.healthLevel.shouldBe 100
  }
  then "The character should have the name 'Thorr'" {
    character.firstName.shouldBeEqualTo 'Thorr'
  }
}

I know which *I* think wins in oh so many ways: clarity, ease of preparation, lack of strange conventions (all those annotations and strange names…IMHO not so good). Recall from my earlier posting the idea that perhaps a Product Owner or Domain Expert could write an easyb story which is then passed on to a developer for further elaboration. Could that be done with either the EasySpec or BDoc versions? I have strong doubts!

For those absolutely wedded to JUnit, it is probably worth mentioning TestDox, which can help to make documentary sense of things. The closest ‘competitor’ to easyb is the written-in-ruby rspec.

Again: please don’t think that I am trying to “put down” EasySpec, TestDox, BDoc, etc., but it just seems to me that there can be a better way…

Tags:

Java Enterprise Edition, JEE, JavaServer Pages, JSP, Tag Libraries, Servlets, Enterprise Java Beans, EJB, Java Messaging Service JMS, BEA Weblogic, JBoss, Application Servers, Spring Framework, Groovy, Grails, Griffon, Seam, Open Source, Service Oriented Architectures, SOA, Java 2 Standard Edition, J2SE