[B]ehavior [D]riven [D]evelopment
By
AGENDA
- Who is this new Indian guy?
- BDD
- Why? What? How?
- Spock Framework
- Why? What? How?
- Demos
- No Questions Please..
Who Am I?
Dhiraj Mahapatro
Grails Developer @ NetJets
twitter # @dhirajmahapatro
GitHub # http://bit.ly/1b07DuM
Stackoverflow# dmahapatro
BDD facilitates writing correct code
Why BDD when we follow TDD?
TDD facilitates writing code correct
TDD Approach
@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.
We tested:
- Code works correctly!!! [Peace]
- Unit test passes!!!
- Who cares about business acceptance criteria?
But we never tested:
- Do we really want "Hello World" back from action?
- Did we actually meet the acceptance criteria?
- The behavior of the application?
RESULT >>
Unhappy BA
Solution
Be Cognizant of the behavior [3 Amigos]
Development based on Behavior
Behavior Based Test Case
@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' } }
How to do that in Grails or Groovy or Java?
Introducing
Spock Framework
Creator
Peter Niederwieser
twitter # @pniedrw
Address Pain Points
- Adhere to BDD
- Easy mocking API
- Easy Stubbing API
- Fine Grained testing
- Above all, its Groovier.
Types of Testing
- Data Driven
- Interaction Based
Sources
@Spock Framework Docs:
@BDD Definition:
@Google Code:
@Github
Thank You
bdd-spock
By Dhiraj Mahapatro
bdd-spock
Presentation on BDD by Spock Framework
- 1,734