Who is this new Indian guy?
BDD
Why? What? How?
Spock Framework
Demo
No Questions Please..
Dhiraj Mahapatro
Grails Developer @ NetJets
twitter # @dhirajmahapatro
GitHub # dmahapatro
Stackoverflow # dmahapatro
Why BDD when we follow TDD?
TDD facilitates writing code correct
BDD facilitates writing correct code
@TestFor(SampleController)
@Mock(Sample)
class SampleControllerTests {
void testControllerActionShowReturnsString() {
//Create mocked object instance
new Sample(name: 'Sample')
//Call controller action
controller.show()
//Assert response
assert controller.response.contentAsString == 'Hello World'
}
}
Test makes sure the controller action is called and response is got back appropriately.
twitter # @pniedrw
@TestFor(SampleController)
@Mock(Sample)
class SampleControllerTests extends ControllerSpec {
void "test controller should return Grails and Ale"() {
given: "A sample object with name Sample"
new Sample(name: 'Sample')
when: "Controller show action is called"
controller.show()
then: "The response should be Grails and Ale"
controller.response.contentAsString == 'Grails and Ale'
}
}
Self documented test matching laid out specification
@Spock Framework Docs:
@BDD Definition:
@Google Code:
@Github