Date: 03 Jun 2014
S(i|a)mple Application: NumberTranslator:
https://bitbucket.org/vpalepu/191b
Q. How do you test/verify behaviors?
- think about or in terms of behaviors.
- actually verify behaviors.
Q. How do you think about behaviors?
(what do i mean by that?)
old school testing demo: https://bitbucket.org/vpalepu/191b
âIntroducing BDDâ by Dan North.
- Test method names should be sentences
- An expressive test name is helpful when a test fails
- âBehaviourâ is a more useful word than âtestâ
- Emphasize behavior over testing
- Determine the next most important behavior
- Think: âwhat should the system should do?â;
- Not: âis the system right?â
- It is all about templates
- A simple sentence template keeps test methods focused
- The class should do something
-
Story/Behavior Templates:
As a [X]
I want [Y]
so that [Z]
Given [some initial context (the givens)],
When [an event occurs],
then [ensure some outcomes].
Q. So are we really verifying behaviors with BDD?
(what do i mean by that?)
State vs Interactions
- Most testing that we do is state based or value based testing. The issue with state based testing is that sometimes you can arrive at the right state with the wrong steps or interactions.
- Process over Results
- The basic idea behind BDD is to think in terms of behaviors; you still might be doing the same old state or value based testing.
- So, BDD does not force test to Behaviors in terms of the actual interactions.
Mocking - testing interactions.
- Mocks enable us to test interactions.
- Mocks are not Stubs or Fakes or Dummies.
Martin Fowler - âMocks Arenât Stubsâ
http://martinfowler.com/articles/mocksArentStubs.html
Fun Reads:
- âMock Roles, not Objectsâ, Freeman, Pryce, Mackinnon, Walnes, OOPSLA 2004.
- âMocks Arenât Stubsâ, Martin Fowler, martinfowler.com/articles/mocksArentStubs.html
- âIntroducing BDDâ, Dan North, dannorth.net/introducing-bdd
- âexpect-run-verify⌠Goodbye!â, http://monkeyisland.pl/2008/02/01/deathwish/
- Mockito Tutorials: http://docs.mockito.googlecode.com/hg/latest/org/mockito/Mockito.html
Other Notes:
- Mockito cannot mock final classes ⌠String, Integer, Scanner
- Last stub always wins
- Mockito uses a âverify what you wantâ philosophy for mocking, unlike most other mocking frameworks that use the âexpect-run-verifyâ philosophy for mocking. more: âexpect-run-verify⌠Goodbye!â, http://monkeyisland.pl/2008/02/01/deathwish/.