Grails Stories
Dependency :
compile ":grails-stories:0.16"
Summary
Installation
grails install-plugin grails-stories
Description
Stories
Stories is a BDD plugin for Grails that aims to make you life easier with functional testing. Stories does't depend on any testing framework out there. It tries to use them all, offerind a way to organize your tests as Stories and Scenarios. What you do inside each scenario is your problem :)… you can use either Selenium, WebTest, HtmlUnit, etc.Using
To install just type:grails install-plugin http://github.com/downloads/xetorthio/stories/grails-stories-0.15.zip
grails create-story SomeStory
story "This is a story", { before { //TODO: do something before every scenario } after { //TODO: do something after every scenario } scenario "This is one scenario", { assert 1 == 1 } scenario "This is another scenario", { assert 1 == 0 } }
-------------------------------------------------------
Running 2 stories tests…
This is a story
A scenario in the story - PASSED
Another scenario in the story - FAILED..... Expression: (1 == 0)
Tests Completed in 46ms …
-------------------------------------------------------
Tests passed: 1
Tests failed: 1
-------------------------------------------------------Testing a REST API
This seems to be a hot topic right now. So lets do that with Storis! As I said earlier, stories actually doesn't provide any specific language to write your tests. It's just a way to organize yourself (and in the future there will be some nice helpers for specific things :) ). So in this example I will use groovy RestClient. In grails this is provided through a plugin called "rest".grails install-plugin restgrails create-story FacebookTest
story "As a consumer I want to get details of a user so I can show the user information in my own site", { scenario "Get user information anonymously without filtering", { get (resource:"https://graph.facebook.com/jleibiusky") { assert status == 200 assert data.name == "Jonathan Leibiusky" assert data.first_name == "Jonathan" } } scenario "Get user information anonymously filtering by fields", { get (resource:"https://graph.facebook.com/jleibiusky", query:[fields:"name"]) { assert status == 200 assert data.name == "Jonathan Leibiusky" assert data.first_name == null } } }