SlideShare una empresa de Scribd logo
1 de 13
Introduction to BDD
Late Debugging
• ???
Unit testing and Module testing
• In unit testing, developers create small tests
during development to check correct behavior
of software

• In module testing, dedicated testers test
software thoroughly after development
What is TDD?
• Test Driven Development
• In TDD, we write unit test before writing
actual code, and then we write the code so
that they pass the test
• This process is known as Red-Green-Refactor
process
Red-Green-Refactor

Write/run test
and see it fail

Add code to
make it pass

Refactor code
for further
improvement
What is BDD?
• Behavior Driven Development
• BDD focuses on the behaviors of software that
are most important to the customers. In BDD,
customers are actively involved in the
development process by means of User stories
BDD User Stories
• BDD user stories are usually written in this
format
Story: [Title]
As [Role]
I want [Feature]
To [Benefit]

Story: [I buy juice]
As [a thirsty person]
I want [to buy juice]
To [drink it and stay hydrated]

Scenario1: [Title]
Given [Context]
AND [Other Context]
When [Event]
Then [Outcome]
AND [Other Outcome]

Scenario1: [Enough money & near vending machine]
Given [I have enough money]
AND [I have access to vending machine]
When [I put money and select juice]
Then [I should get the juice]
AND [I should be able to drink it]
What is Mocha.JS?
• Mocha.js is a testing framework for javascript
that runs on both browser and Node.js server
• Using Mocha, we usually write test code for
each functions of our source code. We can tell
mocha to report error when the output of a
test is a certain value
Mocha.JS client example
(test.html)
<html>
<head>
<title>Mocha Tests</title>
<link rel="stylesheet" href="mocha.css" /> <!– load the mocha css file -->
</head>
<body>
<div id="mocha"></div>
<script src="jquery.js"></script>
<script>function assert(expr, msg) {if (!expr) throw new Error(msg || 'failed');}
</script> <!– assertion method -->
<script src="mocha.js"></script> <!– load the mocha.js library -->
<script>mocha.setup('bdd')</script> <!– setup mocha.js to use BDD style -->
<script src="test.array.js"></script> <!– an example test that tests array -->
<script src="test.object.js"></script> <!– an example test that tests objects -->
<script src="test.xhr.js"></script> <!– an example test that tests xhr -->
<script>
mocha.checkLeaks();
mocha.globals(['jQuery']);
mocha.run(); <!– start the test -->
</script>
</body>
</html>
How to write a Mocha.js test
(test.array.js)
describe('Array', function(){ //test suite for array object
describe('#pop()', function(){ //test suite for pop method
it('should remove and return the last value', function(){ //a test case
var arr = [1,2,3];
assert(arr.pop() == 3); //pop method removes the last element and returns it
assert(arr.pop() == 2);
assert(arr.pop() == -1); //this will generate error since it should be 1 not -1
})

it('should adjust .length', function(){ //another test case
var arr = [1,2,3];
arr.pop();
assert(arr.length == 2);
})
})
})
Mocha.js and assertion libraries
• The assert function in the previous works like
this:
function assert(expr, msg) {
//if expr is false, throw error
if (!expr) throw new Error(msg || 'failed');
}

• But we can also use assertion libraries like
should.js, expect.js, chai.js etc
The test (test.array.js) rewritten
using chai.js
describe('Array', function(){ //test suite for array object
describe('#pop()', function(){ //test suite for pop method
it('should remove and return the last value', function(){ //a test case
var arr = [1,2,3];
arr.pop().should.equal(3);
arr.pop().should.equal(2);
arr.pop().should.equal(-1); //generate error
})

it('should adjust .length', function(){ //another test case
var arr = [1,2,3];
arr.pop();
arr.length.should.equal(2)
})
})
})
UI Testing
• When we develop a software with graphical
user interface, it also becomes necessary to
test that the interface behaves correctly in
addition to testing the behaviors of functions
• However, since it becomes a tedious task to
manually operate and test intereface manually
everytime you change code, automated
testing frameworks are created

Más contenido relacionado

La actualidad más candente

La actualidad más candente (8)

Testing Ext JS and Sencha Touch
Testing Ext JS and Sencha TouchTesting Ext JS and Sencha Touch
Testing Ext JS and Sencha Touch
 
Requirejs
RequirejsRequirejs
Requirejs
 
BDD in Drupal 8 Using Behat, mink and Selenium
BDD in Drupal 8 Using Behat, mink and SeleniumBDD in Drupal 8 Using Behat, mink and Selenium
BDD in Drupal 8 Using Behat, mink and Selenium
 
Managing JavaScript Dependencies With RequireJS
Managing JavaScript Dependencies With RequireJSManaging JavaScript Dependencies With RequireJS
Managing JavaScript Dependencies With RequireJS
 
Odoo Experience 2018 - Odoo Studio as a Prototyping Tool
Odoo Experience 2018 - Odoo Studio as a Prototyping ToolOdoo Experience 2018 - Odoo Studio as a Prototyping Tool
Odoo Experience 2018 - Odoo Studio as a Prototyping Tool
 
Сергей Больщиков "Protractor Tips & Tricks"
Сергей Больщиков "Protractor Tips & Tricks"Сергей Больщиков "Protractor Tips & Tricks"
Сергей Больщиков "Protractor Tips & Tricks"
 
2015 in tothebox-introtddbdd
2015 in tothebox-introtddbdd2015 in tothebox-introtddbdd
2015 in tothebox-introtddbdd
 
Nagios Conference 2014 - Troy Lea - JavaScript and jQuery - Nagios XI Tips, T...
Nagios Conference 2014 - Troy Lea - JavaScript and jQuery - Nagios XI Tips, T...Nagios Conference 2014 - Troy Lea - JavaScript and jQuery - Nagios XI Tips, T...
Nagios Conference 2014 - Troy Lea - JavaScript and jQuery - Nagios XI Tips, T...
 

Destacado

Unit Testing Best Practices
Unit Testing Best PracticesUnit Testing Best Practices
Unit Testing Best Practices
Tomaš Maconko
 
Масштабирование Agile/Lean разработки в рамках программы (Александр Якима)
Масштабирование Agile/Lean разработки в рамках программы (Александр Якима)Масштабирование Agile/Lean разработки в рамках программы (Александр Якима)
Масштабирование Agile/Lean разработки в рамках программы (Александр Якима)
Ontico
 

Destacado (20)

Born Digital - Dan Franklin
Born Digital - Dan FranklinBorn Digital - Dan Franklin
Born Digital - Dan Franklin
 
Unit Testing Best Practices
Unit Testing Best PracticesUnit Testing Best Practices
Unit Testing Best Practices
 
Productivity tips for tech professionals
Productivity tips for tech professionalsProductivity tips for tech professionals
Productivity tips for tech professionals
 
Behaviour driven development aka bdd
Behaviour driven development aka bddBehaviour driven development aka bdd
Behaviour driven development aka bdd
 
Unit testing best practices with JUnit
Unit testing best practices with JUnitUnit testing best practices with JUnit
Unit testing best practices with JUnit
 
Test Automation Framework with BDD and Cucumber
Test Automation Framework with BDD and CucumberTest Automation Framework with BDD and Cucumber
Test Automation Framework with BDD and Cucumber
 
Agile масштабирование компании
Agile масштабирование компанииAgile масштабирование компании
Agile масштабирование компании
 
BDD - beyond: Given, When and Then
BDD - beyond: Given, When and ThenBDD - beyond: Given, When and Then
BDD - beyond: Given, When and Then
 
Масштабирование Agile: Challenge Accepted
Масштабирование Agile: Challenge Accepted Масштабирование Agile: Challenge Accepted
Масштабирование Agile: Challenge Accepted
 
Mocha.js
Mocha.jsMocha.js
Mocha.js
 
Frontend Operations
Frontend OperationsFrontend Operations
Frontend Operations
 
Масштабирование Agile/Lean разработки в рамках программы (Александр Якима)
Масштабирование Agile/Lean разработки в рамках программы (Александр Якима)Масштабирование Agile/Lean разработки в рамках программы (Александр Якима)
Масштабирование Agile/Lean разработки в рамках программы (Александр Якима)
 
Web based automation testing on Node.js environment
Web based automation testing on Node.js environmentWeb based automation testing on Node.js environment
Web based automation testing on Node.js environment
 
Scrum Bangalore 13th meet up 13 june 2015 - behaviour driven development - vi...
Scrum Bangalore 13th meet up 13 june 2015 - behaviour driven development - vi...Scrum Bangalore 13th meet up 13 june 2015 - behaviour driven development - vi...
Scrum Bangalore 13th meet up 13 june 2015 - behaviour driven development - vi...
 
Making the Move to Behavior Driven Development
Making the Move to Behavior Driven DevelopmentMaking the Move to Behavior Driven Development
Making the Move to Behavior Driven Development
 
The Road To Redux
The Road To ReduxThe Road To Redux
The Road To Redux
 
Test Automation With Cucumber JVM, Selenium, and Mocha
Test Automation With Cucumber JVM, Selenium, and MochaTest Automation With Cucumber JVM, Selenium, and Mocha
Test Automation With Cucumber JVM, Selenium, and Mocha
 
Postman Collection Format v2.0 (pre-draft)
Postman Collection Format v2.0 (pre-draft)Postman Collection Format v2.0 (pre-draft)
Postman Collection Format v2.0 (pre-draft)
 
Introduction to Bdd and cucumber
Introduction to Bdd and cucumberIntroduction to Bdd and cucumber
Introduction to Bdd and cucumber
 
Using CI for continuous delivery Part 1
Using CI for continuous delivery Part 1Using CI for continuous delivery Part 1
Using CI for continuous delivery Part 1
 

Similar a Introduction to bdd

Intro To JavaScript Unit Testing - Ran Mizrahi
Intro To JavaScript Unit Testing - Ran MizrahiIntro To JavaScript Unit Testing - Ran Mizrahi
Intro To JavaScript Unit Testing - Ran Mizrahi
Ran Mizrahi
 
Introduction to Unit Testing, BDD and Mocking using TestBox & MockBox at Into...
Introduction to Unit Testing, BDD and Mocking using TestBox & MockBox at Into...Introduction to Unit Testing, BDD and Mocking using TestBox & MockBox at Into...
Introduction to Unit Testing, BDD and Mocking using TestBox & MockBox at Into...
Ortus Solutions, Corp
 

Similar a Introduction to bdd (20)

Intro To JavaScript Unit Testing - Ran Mizrahi
Intro To JavaScript Unit Testing - Ran MizrahiIntro To JavaScript Unit Testing - Ran Mizrahi
Intro To JavaScript Unit Testing - Ran Mizrahi
 
Perl Behavior Driven Development (BDD)
Perl Behavior Driven Development (BDD)Perl Behavior Driven Development (BDD)
Perl Behavior Driven Development (BDD)
 
Cucumber - use it to describe user stories and acceptance criterias
Cucumber - use it to describe user stories and acceptance criteriasCucumber - use it to describe user stories and acceptance criterias
Cucumber - use it to describe user stories and acceptance criterias
 
Database continuous integration, unit test and functional test
Database continuous integration, unit test and functional testDatabase continuous integration, unit test and functional test
Database continuous integration, unit test and functional test
 
2014 11 20 Drupal 7 -> 8 test migratie
2014 11 20 Drupal 7 -> 8 test migratie2014 11 20 Drupal 7 -> 8 test migratie
2014 11 20 Drupal 7 -> 8 test migratie
 
Testing - How Vital and How Easy to use
Testing - How Vital and How Easy to useTesting - How Vital and How Easy to use
Testing - How Vital and How Easy to use
 
Introduction to Unit Testing, BDD and Mocking using TestBox & MockBox at Into...
Introduction to Unit Testing, BDD and Mocking using TestBox & MockBox at Into...Introduction to Unit Testing, BDD and Mocking using TestBox & MockBox at Into...
Introduction to Unit Testing, BDD and Mocking using TestBox & MockBox at Into...
 
Behavior Driven Development by Example
Behavior Driven Development by ExampleBehavior Driven Development by Example
Behavior Driven Development by Example
 
Introduction to Unit Testing, BDD and Mocking using TestBox & MockBox at Adob...
Introduction to Unit Testing, BDD and Mocking using TestBox & MockBox at Adob...Introduction to Unit Testing, BDD and Mocking using TestBox & MockBox at Adob...
Introduction to Unit Testing, BDD and Mocking using TestBox & MockBox at Adob...
 
German Testing Day 2015 - How behavior-driven development fuses developers an...
German Testing Day 2015 - How behavior-driven development fuses developers an...German Testing Day 2015 - How behavior-driven development fuses developers an...
German Testing Day 2015 - How behavior-driven development fuses developers an...
 
Cucumber_Training_ForQA
Cucumber_Training_ForQACucumber_Training_ForQA
Cucumber_Training_ForQA
 
BDD Selenium for Agile Teams - User Stories
BDD Selenium for Agile Teams - User StoriesBDD Selenium for Agile Teams - User Stories
BDD Selenium for Agile Teams - User Stories
 
3 WAYS TO TEST YOUR COLDFUSION API -
3 WAYS TO TEST YOUR COLDFUSION API - 3 WAYS TO TEST YOUR COLDFUSION API -
3 WAYS TO TEST YOUR COLDFUSION API -
 
3 WAYS TO TEST YOUR COLDFUSION API
3 WAYS TO TEST YOUR COLDFUSION API3 WAYS TO TEST YOUR COLDFUSION API
3 WAYS TO TEST YOUR COLDFUSION API
 
Zend
ZendZend
Zend
 
Useful practices of creation automatic tests by using cucumber jvm
Useful practices of creation automatic tests by using cucumber jvmUseful practices of creation automatic tests by using cucumber jvm
Useful practices of creation automatic tests by using cucumber jvm
 
How to JavaOne 2016 - Generate Customized Java 8 Code from Your Database [TUT...
How to JavaOne 2016 - Generate Customized Java 8 Code from Your Database [TUT...How to JavaOne 2016 - Generate Customized Java 8 Code from Your Database [TUT...
How to JavaOne 2016 - Generate Customized Java 8 Code from Your Database [TUT...
 
JavaOne2016 - How to Generate Customized Java 8 Code from Your Database [TUT4...
JavaOne2016 - How to Generate Customized Java 8 Code from Your Database [TUT4...JavaOne2016 - How to Generate Customized Java 8 Code from Your Database [TUT4...
JavaOne2016 - How to Generate Customized Java 8 Code from Your Database [TUT4...
 
Continuous Quality
Continuous QualityContinuous Quality
Continuous Quality
 
How to generate customized java 8 code from your database
How to generate customized java 8 code from your databaseHow to generate customized java 8 code from your database
How to generate customized java 8 code from your database
 

Último

The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
heathfieldcps1
 

Último (20)

Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptx
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
Plant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxPlant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptx
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 

Introduction to bdd

  • 3. Unit testing and Module testing • In unit testing, developers create small tests during development to check correct behavior of software • In module testing, dedicated testers test software thoroughly after development
  • 4. What is TDD? • Test Driven Development • In TDD, we write unit test before writing actual code, and then we write the code so that they pass the test • This process is known as Red-Green-Refactor process
  • 5. Red-Green-Refactor Write/run test and see it fail Add code to make it pass Refactor code for further improvement
  • 6. What is BDD? • Behavior Driven Development • BDD focuses on the behaviors of software that are most important to the customers. In BDD, customers are actively involved in the development process by means of User stories
  • 7. BDD User Stories • BDD user stories are usually written in this format Story: [Title] As [Role] I want [Feature] To [Benefit] Story: [I buy juice] As [a thirsty person] I want [to buy juice] To [drink it and stay hydrated] Scenario1: [Title] Given [Context] AND [Other Context] When [Event] Then [Outcome] AND [Other Outcome] Scenario1: [Enough money & near vending machine] Given [I have enough money] AND [I have access to vending machine] When [I put money and select juice] Then [I should get the juice] AND [I should be able to drink it]
  • 8. What is Mocha.JS? • Mocha.js is a testing framework for javascript that runs on both browser and Node.js server • Using Mocha, we usually write test code for each functions of our source code. We can tell mocha to report error when the output of a test is a certain value
  • 9. Mocha.JS client example (test.html) <html> <head> <title>Mocha Tests</title> <link rel="stylesheet" href="mocha.css" /> <!– load the mocha css file --> </head> <body> <div id="mocha"></div> <script src="jquery.js"></script> <script>function assert(expr, msg) {if (!expr) throw new Error(msg || 'failed');} </script> <!– assertion method --> <script src="mocha.js"></script> <!– load the mocha.js library --> <script>mocha.setup('bdd')</script> <!– setup mocha.js to use BDD style --> <script src="test.array.js"></script> <!– an example test that tests array --> <script src="test.object.js"></script> <!– an example test that tests objects --> <script src="test.xhr.js"></script> <!– an example test that tests xhr --> <script> mocha.checkLeaks(); mocha.globals(['jQuery']); mocha.run(); <!– start the test --> </script> </body> </html>
  • 10. How to write a Mocha.js test (test.array.js) describe('Array', function(){ //test suite for array object describe('#pop()', function(){ //test suite for pop method it('should remove and return the last value', function(){ //a test case var arr = [1,2,3]; assert(arr.pop() == 3); //pop method removes the last element and returns it assert(arr.pop() == 2); assert(arr.pop() == -1); //this will generate error since it should be 1 not -1 }) it('should adjust .length', function(){ //another test case var arr = [1,2,3]; arr.pop(); assert(arr.length == 2); }) }) })
  • 11. Mocha.js and assertion libraries • The assert function in the previous works like this: function assert(expr, msg) { //if expr is false, throw error if (!expr) throw new Error(msg || 'failed'); } • But we can also use assertion libraries like should.js, expect.js, chai.js etc
  • 12. The test (test.array.js) rewritten using chai.js describe('Array', function(){ //test suite for array object describe('#pop()', function(){ //test suite for pop method it('should remove and return the last value', function(){ //a test case var arr = [1,2,3]; arr.pop().should.equal(3); arr.pop().should.equal(2); arr.pop().should.equal(-1); //generate error }) it('should adjust .length', function(){ //another test case var arr = [1,2,3]; arr.pop(); arr.length.should.equal(2) }) }) })
  • 13. UI Testing • When we develop a software with graphical user interface, it also becomes necessary to test that the interface behaves correctly in addition to testing the behaviors of functions • However, since it becomes a tedious task to manually operate and test intereface manually everytime you change code, automated testing frameworks are created