Have you ever read about easyb? and about Grails? May be you answer yes to one or both previous questions, but this is the first time you will find them together I guarantee, at least in a plugin form.
This is the first post I’m writing about my latest toy project (at least for now it is only a toy project).
The project is hosted at GitHub, and any help will be very welcome since I do not work every day with Grails, but I did a presentation about grails in the last weekend and wanted to use BDD instead of the traditional GUnit based unit tests, I already use Easyb for some of my Java projects, then I wanted to make Easyb and Grails to work together.
It was not an easy task, because of some craziness of Grails class loader, but it is working fine now.
You can write a test with the easyb sintaxe, and the test will look line this:
scenario "Project creation", { given "A new project", { project = new Project() } when "the project name is supplied", { project.name = 'My test project' } and "there is no other project with that name", { validateproject = { project.validate().shouldBe true } } then "a new project must be created", { validateproject() project.save(flush:true).shouldNotBe null } } scenario "User association with a project", { given "Any existing project", { project = Project.findAll()[0] } when "a list of users is supplied", { users = [new User(login:'testUser1',password:'testUser1',email:'test1@test.com').save(),new User(login:'testUser2',password:'testUser2',email:'test2@test.com').save()] } then "the users must be associated with that project", { users.each{ ProjectMembership.link(it,project) } } }
You can even show it to your boss, because the output of this test is some thing like this:
Story: project management
scenario Project creation
given A new project
when the project name is supplied
when there is no other project with that name
then a new project must be createdscenario User association with a project
given Any existing project
when a list of users is supplied
then the users must be associated with that project
And the best part of it, is that you can use your tests as the specifications of your next grails project!
If you want to know more about the easyb sintax, take a look at the project site.
If you want to know more about grails, take a look at the project site.
If you want a new functionality in this plugin, I’ll probably accept all patches and push requests you send-me ![]()
And finally, if you want to install the plugin, download it from here and run:
grails install-plugin grails-easybtest-latest.zip
You will need to place the tests you write in the folder tests/behavior
And to run the tests, just type: grails easyb-test
Any doubts or suggestions leave a comment here ![]()
I hope it can be useful to others.
If you enjoyed this post, make sure you subscribe to my RSS feed!
Tags: easyb, easyb-test, grails, petproject, plugin, test