Share
Embed
Introduction to TDD and BDD
Introduction to TDD and BDD
Presented to my colleagues at ING Direct Spain
Luis GC
June 08, 2016
Transcript
22 slides
-
TESTING 2 Why is testing so important ? We can’t
avoid to have bugs in our applications, but we must limit its presence and impact (and not only in release date) Inception Design Development Acceptance Maintenance -
3 Benefits of Unit Testing Tests create a feedback loop
that informs the developer whether the product is working or not. • Unit tests are fast • Unit tests are reliable • Unit tests isolate failures But tests made at the end of the project are only useful to exceed the mandatory coverage, they don’t provide many other benefits -
4 What is TDD ? TDD is a not just
“adding tests first”, it’s a workflow -
5 Benefits of TDD TDD is the best way to
discover how complex your code is becoming • Do you need to mock 7 objects for a unit test? • Do you have a setup method of >15 lines? • Are you able to test all your code? By writing test first: • You are becoming a consumer of your own API • You are forced to think what responsibilities the given object should have • You are creating a safety net for everyone -
Acceptance tests Customer tests … BDD Unit tests TDD Sonar
Lint ... 6 Is it enough with unit tests ? Code Right vs Right Code -
7 What is BDD ? Behaviour-Driven Development “It’s about focusing
on the behaviour of an application from the point of view of its stakeholders” Dan North -
8 Who is a stakeholder ? A stakeholder is anyone
who cares about: • What the application does • How much it costs • Whether it is secure • Whether the network will hold • Whether it complies with the law • How easy it is to deploy and diagnose • How well it is written and architected • How easy it is to change -
9 A more formal definition of BDD BDD is a
second-generation, outside-in, pull-based, multiple- stakeholder, multiple-scale, high-automation, agile methodology It describes a cycle of interactions with well-defined outputs, resulting in the delivery of working, tested software that matters Dan North -
10 BDD asks for an Outside-In approach Express a requirement
as a Story • As… I want… So that I… Define acceptance criteria as scenarios made up of steps • Given… When… Then... Automate the scenarios • So each step becomes running code -
11 BDD is about Comunication Business Team Requirements Examples to
discuss Design and create code specification Examples to implement -
12 Simple requirements and examples Feature: Tracking deliveries As a
Customer I want to see a status of my delivery So I can know when it’s going to be delivered Scenario: Clicking a tracking URL Given I am waiting for a delivery And I received a confirmation message When I click the tracking URL from the message Then I should see a status of my delivery -
13 Gherkin Gherkin is plain-text English (or any other of
the 60+ supported languages) with a little extra structure. Is designed to be easy to learn by non-programmers, yet structured enough to allow concise description of examples to illustrate business rules in most real-world domains. In Gherkin each not-blank line should start with a keyword: Feature, Scenario, Given, When, Then, And, Background, ... -
15 Main benefits of BDD • Examples become unit tests
and documentation • Scenarios become acceptance tests and documentation • Acceptance tests also become regression tests -
16 Benefits of BDD for developers • BDD will help
you focus • BDD will give you confidence to refactor • BDD will help you better undersand the customers needs -
17 Benefits of BDD for Product Owners • BDD will
give you a greater insight into the complexity of what you’re asking for • BDD will give you transparency about what the team is doing in each iteration • BDD will help your teams ship faster -
18 Benefits of BDD for Testers • BDD will mean
you can find bugs even before they have been written • BDD will give you the best automatic regression tests • BDD will free you to do interesting, creative, exploratory testing -
21 Use BDD in almost any language • Java •
Concordion • Easyb • JDave • JBehave • Javascript • Protractor • Jasmine • Cucumber • Python • Behave • Groovy • Cucumber • PHP • Kahlan • Behat • .NET • Concordion