SlideShare a Scribd company logo
Testing Technique 
By:- Arvind Vyas
What is TDD and BDD ?
Test Driven Development
Test Driven Development 
When I first heard about TDD, the idea seemed to be pretty simple. Just by doing a little word swizzling, obviously TDD 
is when you have tests that drive your software development. 
If we were to unpack the definition of TDD a bit more, we'd see that it is usually broken up into five different stages: 
1. First the developer writes some tests. 
2. The developer then runs those tests and (obviously) they fail because none of those features are actually 
implemented. 
3. Next the developer actually implements those tests in code. 
4. If the developer writes his code well, then the in next stage he will see his tests pass.
Flow Chart
Behaviour driven development
BDD 
BDD is meant to eliminate issues that TDD might cause. 
In contrast to TDD, BDD is when we write behavior & 
specification that then drives our software development. 
Behavior & specification might seem awfully similar to 
tests but the difference is very subtle and important.
Example 
#Testing for our User class 
describe User do 
context 'with admin privileges' do 
before :each do 
@admin = Admin.get(1) 
end 
it 'should exist' do 
expect(@admin).not_to be_nil 
end 
it 'should have a name' do 
expect(@admin.name).not_to be_falsy 
end 
end 
#...
Example for TDD and BDD 
approach
var assert = require('assert'), 
factorial = require('../index');suite('Test', function (){ 
setup(function (){ 
// Create any objects that we might need 
}); 
suite('#factorial()', function (){ 
test('equals 1 for sets of zero length', function (){ 
assert.equal(1, factorial(0)); 
}); 
test('equals 1 for sets of length one', function (){ 
assert.equal(1, factorial(1)); 
}); 
test('equals 2 for sets of length two', function (){ 
assert.equal(2, factorial(2)); 
}); 
test('equals 6 for sets of length three', function (){ 
assert.equal(6, factorial(3)); 
}); 
});});
var assert = require('assert'), 
factorial = require('../index');describe('Test', function (){ 
before(function(){ 
// Stuff to do before the tests, like imports, what not 
}); 
describe('#factorial()', function (){ 
it('should return 1 when given 0', function (){ 
factorial(0).should.equal(1); 
}); 
it('should return 1 when given 1', function (){ 
factorial(1).should.equal(1); 
}); 
it('should return 2 when given 2', function (){ 
factorial(2).should.equal(2); 
}); 
it('should return 6 when given 3', function (){ 
factorial(3).should.equal(6); 
}); 
});
If you have seen the previous example then 
you can find it out that the first example 
for the TDD because inside the developer 
only checking the value of the method 
But if you have observed the second code 
then you will find test are more focus on 
the behaviour.
WHY TESTING ????????
1) By simply running your rails test you can ensure your 
code adheres to the desired functionality even after some 
major code refactoring. 
2) Your application response without having to test it 
through your browser 
3) You can easily upgrade your rails application
Levels of Testing 
● Unit Tests 
● Integration Tests 
● Acceptance Tests
Ready ????
$ ls -F test
controllers/ helpers/ mailers/ 
test_helper.rb fixtures/ integration/ 
models/
Unit Test??? 
$ rails new TestingTime 
$rails generate scaffold profile 
title:string body:text 
$ rake test test/models/profile_test.rb
require 'test_helper' 
class ProfileTest < ActiveSupport::TestCase 
test "the truth" do 
assert true 
end 
test "should not have Profile with title" do 
profile = Profile.new 
assert_not profile.save # save the title 
without title 
end 
test "should not have profile without body" do 
profile = Profile.new 
profile.title = 'Arvind' 
assert_not profile.save # save the body without 
title 
end 
end 
class Profile < ActiveRecord::Base 
class Post < ActiveRecord::Base 
validates :title, :body, presence: true 
validates :title, :body, presence: true 
end 
end 
$ rake test test/models/post_test.rb
Controllers ?? 
Testing the various actions of a single 
controller is called writing functional tests 
for that controller. 
Controllers handle the incoming web 
requests to your application and eventually 
respond with a rendered view.
require 'test_helper' 
class ProfilerofileControllerTest < ActionController::TestCase 
setup do 
@rofileprofile = rofilesprofile(:one) 
end 
test "should get index" do 
get :index 
assert_response :success 
assert_not_nil assigns(:profile) 
end 
test "should get new" do 
get :new 
assert_response :success 
end 
test "should create rofileprofile" do 
assert_difference('Profilerofile.count') do 
post :create, profile: {title: @profrofile.title, body: @profile.body} 
end 
assert_redirected_to profile_path(assigns(:profile)) 
assert_equal 'Profile was successfully created.', flash[:notice] 
end
#run all the test case which are inside test 
$ rake test test 
i
What to include in your 
functional test 
->Web request successful 
-> User redirect to the right place 
-> User successfully authenticated 
-> Correct object stored in the response 
template 
- > Appropriate message displayed
A Last question for all 
What is the use of integration folder in 
testing what we put on that ?? ????
TDD & BDD

More Related Content

What's hot

Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
Consulthinkspa
 
TDD - Test Driven Development
TDD - Test Driven DevelopmentTDD - Test Driven Development
TDD - Test Driven Development
Tung Nguyen Thanh
 
Living With Legacy Code
Living With Legacy CodeLiving With Legacy Code
Living With Legacy Code
Rowan Merewood
 
Introduction to TDD (Test Driven development) - Ahmed Shreef
Introduction to TDD (Test Driven development) - Ahmed ShreefIntroduction to TDD (Test Driven development) - Ahmed Shreef
Introduction to TDD (Test Driven development) - Ahmed Shreef
Ahmed Shreef
 
TDD and Simple Design Workshop - Session 1 - March 2019
TDD and Simple Design Workshop - Session 1 - March 2019TDD and Simple Design Workshop - Session 1 - March 2019
TDD and Simple Design Workshop - Session 1 - March 2019
Paulo Clavijo
 
Refactoring Legacy Code
Refactoring Legacy CodeRefactoring Legacy Code
Refactoring Legacy Code
Adam Culp
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
guestc8093a6
 
Introduction to Behavior Driven Development
Introduction to Behavior Driven Development Introduction to Behavior Driven Development
Introduction to Behavior Driven Development
Robin O'Brien
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
Sachithra Gayan
 
TDD (Test Driven Design)
TDD (Test Driven Design)TDD (Test Driven Design)
TDD (Test Driven Design)
nedirtv
 
Test-Driven Development (TDD)
Test-Driven Development (TDD)Test-Driven Development (TDD)
Test-Driven Development (TDD)
Brian Rasmussen
 
Acceptance Test Driven Development With Spec Flow And Friends
Acceptance Test Driven Development With Spec Flow And FriendsAcceptance Test Driven Development With Spec Flow And Friends
Acceptance Test Driven Development With Spec Flow And Friends
Christopher Bartling
 
2015 in tothebox-introtddbdd
2015 in tothebox-introtddbdd2015 in tothebox-introtddbdd
2015 in tothebox-introtddbdd
ColdFusionConference
 
TDD - Agile
TDD - Agile TDD - Agile
TDD - Agile
harinderpisces
 
Pitfalls Of Tdd Adoption by Bartosz Bankowski
Pitfalls Of Tdd Adoption by Bartosz BankowskiPitfalls Of Tdd Adoption by Bartosz Bankowski
Pitfalls Of Tdd Adoption by Bartosz Bankowski
Agileee
 
Writing useful automated tests for the single page applications you build
Writing useful automated tests for the single page applications you buildWriting useful automated tests for the single page applications you build
Writing useful automated tests for the single page applications you build
Andrei Sebastian Cîmpean
 
Behavior Driven Development with SpecFlow
Behavior Driven Development with SpecFlowBehavior Driven Development with SpecFlow
Behavior Driven Development with SpecFlow
Rachid Kherrazi
 
TDD CrashCourse Part3: TDD Techniques
TDD CrashCourse Part3: TDD TechniquesTDD CrashCourse Part3: TDD Techniques
TDD CrashCourse Part3: TDD Techniques
David Rodenas
 
An Introduction to Test Driven Development
An Introduction to Test Driven Development An Introduction to Test Driven Development
An Introduction to Test Driven Development
CodeOps Technologies LLP
 
3 Ways to test your ColdFusion API - 2017 Adobe CF Summit
3 Ways to test your ColdFusion API - 2017 Adobe CF Summit3 Ways to test your ColdFusion API - 2017 Adobe CF Summit
3 Ways to test your ColdFusion API - 2017 Adobe CF Summit
Ortus Solutions, Corp
 

What's hot (20)

Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
TDD - Test Driven Development
TDD - Test Driven DevelopmentTDD - Test Driven Development
TDD - Test Driven Development
 
Living With Legacy Code
Living With Legacy CodeLiving With Legacy Code
Living With Legacy Code
 
Introduction to TDD (Test Driven development) - Ahmed Shreef
Introduction to TDD (Test Driven development) - Ahmed ShreefIntroduction to TDD (Test Driven development) - Ahmed Shreef
Introduction to TDD (Test Driven development) - Ahmed Shreef
 
TDD and Simple Design Workshop - Session 1 - March 2019
TDD and Simple Design Workshop - Session 1 - March 2019TDD and Simple Design Workshop - Session 1 - March 2019
TDD and Simple Design Workshop - Session 1 - March 2019
 
Refactoring Legacy Code
Refactoring Legacy CodeRefactoring Legacy Code
Refactoring Legacy Code
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
Introduction to Behavior Driven Development
Introduction to Behavior Driven Development Introduction to Behavior Driven Development
Introduction to Behavior Driven Development
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
TDD (Test Driven Design)
TDD (Test Driven Design)TDD (Test Driven Design)
TDD (Test Driven Design)
 
Test-Driven Development (TDD)
Test-Driven Development (TDD)Test-Driven Development (TDD)
Test-Driven Development (TDD)
 
Acceptance Test Driven Development With Spec Flow And Friends
Acceptance Test Driven Development With Spec Flow And FriendsAcceptance Test Driven Development With Spec Flow And Friends
Acceptance Test Driven Development With Spec Flow And Friends
 
2015 in tothebox-introtddbdd
2015 in tothebox-introtddbdd2015 in tothebox-introtddbdd
2015 in tothebox-introtddbdd
 
TDD - Agile
TDD - Agile TDD - Agile
TDD - Agile
 
Pitfalls Of Tdd Adoption by Bartosz Bankowski
Pitfalls Of Tdd Adoption by Bartosz BankowskiPitfalls Of Tdd Adoption by Bartosz Bankowski
Pitfalls Of Tdd Adoption by Bartosz Bankowski
 
Writing useful automated tests for the single page applications you build
Writing useful automated tests for the single page applications you buildWriting useful automated tests for the single page applications you build
Writing useful automated tests for the single page applications you build
 
Behavior Driven Development with SpecFlow
Behavior Driven Development with SpecFlowBehavior Driven Development with SpecFlow
Behavior Driven Development with SpecFlow
 
TDD CrashCourse Part3: TDD Techniques
TDD CrashCourse Part3: TDD TechniquesTDD CrashCourse Part3: TDD Techniques
TDD CrashCourse Part3: TDD Techniques
 
An Introduction to Test Driven Development
An Introduction to Test Driven Development An Introduction to Test Driven Development
An Introduction to Test Driven Development
 
3 Ways to test your ColdFusion API - 2017 Adobe CF Summit
3 Ways to test your ColdFusion API - 2017 Adobe CF Summit3 Ways to test your ColdFusion API - 2017 Adobe CF Summit
3 Ways to test your ColdFusion API - 2017 Adobe CF Summit
 

Viewers also liked

ODD: Extending a Specification 1.2
ODD: Extending a Specification 1.2ODD: Extending a Specification 1.2
ODD: Extending a Specification 1.2
Jonathan Herring
 
BDD in Action – principles, practices and real-world application
BDD in Action – principles, practices and real-world applicationBDD in Action – principles, practices and real-world application
BDD in Action – principles, practices and real-world application
John Ferguson Smart Limited
 
BDD - Writing better scenario
BDD - Writing better scenarioBDD - Writing better scenario
BDD - Writing better scenario
Arnauld Loyer
 
BDD in Action - building software that matters
BDD in Action - building software that mattersBDD in Action - building software that matters
BDD in Action - building software that matters
John Ferguson Smart Limited
 
Why BDD is misunderstood
Why BDD is misunderstoodWhy BDD is misunderstood
Why BDD is misunderstood
Thoughtworks
 
Pair Programming Talk
Pair Programming TalkPair Programming Talk
Pair Programming Talk
jlangr
 
BDD, Gherkin, Cucumber and why we need it.
BDD, Gherkin, Cucumber and why we need it.BDD, Gherkin, Cucumber and why we need it.
BDD, Gherkin, Cucumber and why we need it.
AlexOsadchyy
 
Xtreme Programming
Xtreme ProgrammingXtreme Programming
Xtreme Programming
NoretSarted
 
XP In 10 slides
XP In 10 slidesXP In 10 slides
XP In 10 slides
Robert Burrell Donkin
 
Bdd: Tdd and beyond the infinite
Bdd: Tdd and beyond the infiniteBdd: Tdd and beyond the infinite
Bdd: Tdd and beyond the infinite
Giordano Scalzo
 
Testcase Preparation Checklist
Testcase Preparation ChecklistTestcase Preparation Checklist
Testcase Preparation Checklist
Sreeram Kishore Chavali
 
TDD in functional testing with WebDriver
TDD in functional testing with WebDriverTDD in functional testing with WebDriver
TDD in functional testing with WebDriver
Mikalai Alimenkou
 
BDD - Collaborate like you mean it!
BDD - Collaborate like you mean it!BDD - Collaborate like you mean it!
BDD - Collaborate like you mean it!
John Ferguson Smart Limited
 
Role of scrum master
Role of scrum masterRole of scrum master
Role of scrum master
Tushar Somaiya
 
Devops
DevopsDevops
Getting Comfortable with BDD
Getting Comfortable with BDDGetting Comfortable with BDD
Getting Comfortable with BDD
Alex Sharp
 
Business Value of Agile Testing: Using TDD, CI, CD, & DevOps
Business Value of Agile Testing: Using TDD, CI, CD, & DevOpsBusiness Value of Agile Testing: Using TDD, CI, CD, & DevOps
Business Value of Agile Testing: Using TDD, CI, CD, & DevOps
David Rico
 
How to be a great scrum master
How to be a great scrum masterHow to be a great scrum master
How to be a great scrum master
Daniel Shupp
 
Business Value of CI, CD, & DevOpsSec: Scaling to Billion User Systems Using ...
Business Value of CI, CD, & DevOpsSec: Scaling to Billion User Systems Using ...Business Value of CI, CD, & DevOpsSec: Scaling to Billion User Systems Using ...
Business Value of CI, CD, & DevOpsSec: Scaling to Billion User Systems Using ...
David Rico
 
The WHY behind TDD/BDD and the HOW with RSpec
The WHY behind TDD/BDD and the HOW with RSpecThe WHY behind TDD/BDD and the HOW with RSpec
The WHY behind TDD/BDD and the HOW with RSpec
Ben Mabey
 

Viewers also liked (20)

ODD: Extending a Specification 1.2
ODD: Extending a Specification 1.2ODD: Extending a Specification 1.2
ODD: Extending a Specification 1.2
 
BDD in Action – principles, practices and real-world application
BDD in Action – principles, practices and real-world applicationBDD in Action – principles, practices and real-world application
BDD in Action – principles, practices and real-world application
 
BDD - Writing better scenario
BDD - Writing better scenarioBDD - Writing better scenario
BDD - Writing better scenario
 
BDD in Action - building software that matters
BDD in Action - building software that mattersBDD in Action - building software that matters
BDD in Action - building software that matters
 
Why BDD is misunderstood
Why BDD is misunderstoodWhy BDD is misunderstood
Why BDD is misunderstood
 
Pair Programming Talk
Pair Programming TalkPair Programming Talk
Pair Programming Talk
 
BDD, Gherkin, Cucumber and why we need it.
BDD, Gherkin, Cucumber and why we need it.BDD, Gherkin, Cucumber and why we need it.
BDD, Gherkin, Cucumber and why we need it.
 
Xtreme Programming
Xtreme ProgrammingXtreme Programming
Xtreme Programming
 
XP In 10 slides
XP In 10 slidesXP In 10 slides
XP In 10 slides
 
Bdd: Tdd and beyond the infinite
Bdd: Tdd and beyond the infiniteBdd: Tdd and beyond the infinite
Bdd: Tdd and beyond the infinite
 
Testcase Preparation Checklist
Testcase Preparation ChecklistTestcase Preparation Checklist
Testcase Preparation Checklist
 
TDD in functional testing with WebDriver
TDD in functional testing with WebDriverTDD in functional testing with WebDriver
TDD in functional testing with WebDriver
 
BDD - Collaborate like you mean it!
BDD - Collaborate like you mean it!BDD - Collaborate like you mean it!
BDD - Collaborate like you mean it!
 
Role of scrum master
Role of scrum masterRole of scrum master
Role of scrum master
 
Devops
DevopsDevops
Devops
 
Getting Comfortable with BDD
Getting Comfortable with BDDGetting Comfortable with BDD
Getting Comfortable with BDD
 
Business Value of Agile Testing: Using TDD, CI, CD, & DevOps
Business Value of Agile Testing: Using TDD, CI, CD, & DevOpsBusiness Value of Agile Testing: Using TDD, CI, CD, & DevOps
Business Value of Agile Testing: Using TDD, CI, CD, & DevOps
 
How to be a great scrum master
How to be a great scrum masterHow to be a great scrum master
How to be a great scrum master
 
Business Value of CI, CD, & DevOpsSec: Scaling to Billion User Systems Using ...
Business Value of CI, CD, & DevOpsSec: Scaling to Billion User Systems Using ...Business Value of CI, CD, & DevOpsSec: Scaling to Billion User Systems Using ...
Business Value of CI, CD, & DevOpsSec: Scaling to Billion User Systems Using ...
 
The WHY behind TDD/BDD and the HOW with RSpec
The WHY behind TDD/BDD and the HOW with RSpecThe WHY behind TDD/BDD and the HOW with RSpec
The WHY behind TDD/BDD and the HOW with RSpec
 

Similar to TDD & BDD

Describe's Full of It's
Describe's Full of It'sDescribe's Full of It's
Describe's Full of It's
Jim Lynch
 
How To Test Everything
How To Test EverythingHow To Test Everything
How To Test Everything
noelrap
 
In search of JavaScript code quality: unit testing
In search of JavaScript code quality: unit testingIn search of JavaScript code quality: unit testing
In search of JavaScript code quality: unit testing
Anna Khabibullina
 
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
 
Rspec
RspecRspec
Quick tour to front end unit testing using jasmine
Quick tour to front end unit testing using jasmineQuick tour to front end unit testing using jasmine
Quick tour to front end unit testing using jasmine
Gil Fink
 
Front end unit testing using jasmine
Front end unit testing using jasmineFront end unit testing using jasmine
Front end unit testing using jasmine
Gil Fink
 
Rtt preso
Rtt presoRtt preso
Rtt preso
fdschoeneman
 
Quick Tour to Front-End Unit Testing Using Jasmine
Quick Tour to Front-End Unit Testing Using JasmineQuick Tour to Front-End Unit Testing Using Jasmine
Quick Tour to Front-End Unit Testing Using Jasmine
Gil Fink
 
Grails unit testing
Grails unit testingGrails unit testing
Grails unit testing
pleeps
 
Intro to Unit Testing in AngularJS
Intro to Unit Testing in AngularJSIntro to Unit Testing in AngularJS
Intro to Unit Testing in AngularJS
Jim Lynch
 
Javascript tdd byandreapaciolla
Javascript tdd byandreapaciollaJavascript tdd byandreapaciolla
Javascript tdd byandreapaciolla
Andrea Paciolla
 
2011-02-03 LA RubyConf Rails3 TDD Workshop
2011-02-03 LA RubyConf Rails3 TDD Workshop2011-02-03 LA RubyConf Rails3 TDD Workshop
2011-02-03 LA RubyConf Rails3 TDD Workshop
Wolfram Arnold
 
We Are All Testers Now: The Testing Pyramid and Front-End Development
We Are All Testers Now: The Testing Pyramid and Front-End DevelopmentWe Are All Testers Now: The Testing Pyramid and Front-End Development
We Are All Testers Now: The Testing Pyramid and Front-End Development
All Things Open
 
Introduction to testing in Rails
Introduction to testing in RailsIntroduction to testing in Rails
Introduction to testing in Rails
benlcollins
 
Typescript barcelona
Typescript barcelonaTypescript barcelona
Typescript barcelona
Christoffer Noring
 
Write codeforhumans
Write codeforhumansWrite codeforhumans
Write codeforhumans
Narendran R
 
Javascript unit testing, yes we can e big
Javascript unit testing, yes we can   e bigJavascript unit testing, yes we can   e big
Javascript unit testing, yes we can e big
Andy Peterson
 
Unit Testing and Coverage for AngularJS
Unit Testing and Coverage for AngularJSUnit Testing and Coverage for AngularJS
Unit Testing and Coverage for AngularJS
Knoldus Inc.
 
Test Coverage in Rails
Test Coverage in RailsTest Coverage in Rails
Test Coverage in Rails
James Gray
 

Similar to TDD & BDD (20)

Describe's Full of It's
Describe's Full of It'sDescribe's Full of It's
Describe's Full of It's
 
How To Test Everything
How To Test EverythingHow To Test Everything
How To Test Everything
 
In search of JavaScript code quality: unit testing
In search of JavaScript code quality: unit testingIn search of JavaScript code quality: unit testing
In search of JavaScript code quality: unit testing
 
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
 
Rspec
RspecRspec
Rspec
 
Quick tour to front end unit testing using jasmine
Quick tour to front end unit testing using jasmineQuick tour to front end unit testing using jasmine
Quick tour to front end unit testing using jasmine
 
Front end unit testing using jasmine
Front end unit testing using jasmineFront end unit testing using jasmine
Front end unit testing using jasmine
 
Rtt preso
Rtt presoRtt preso
Rtt preso
 
Quick Tour to Front-End Unit Testing Using Jasmine
Quick Tour to Front-End Unit Testing Using JasmineQuick Tour to Front-End Unit Testing Using Jasmine
Quick Tour to Front-End Unit Testing Using Jasmine
 
Grails unit testing
Grails unit testingGrails unit testing
Grails unit testing
 
Intro to Unit Testing in AngularJS
Intro to Unit Testing in AngularJSIntro to Unit Testing in AngularJS
Intro to Unit Testing in AngularJS
 
Javascript tdd byandreapaciolla
Javascript tdd byandreapaciollaJavascript tdd byandreapaciolla
Javascript tdd byandreapaciolla
 
2011-02-03 LA RubyConf Rails3 TDD Workshop
2011-02-03 LA RubyConf Rails3 TDD Workshop2011-02-03 LA RubyConf Rails3 TDD Workshop
2011-02-03 LA RubyConf Rails3 TDD Workshop
 
We Are All Testers Now: The Testing Pyramid and Front-End Development
We Are All Testers Now: The Testing Pyramid and Front-End DevelopmentWe Are All Testers Now: The Testing Pyramid and Front-End Development
We Are All Testers Now: The Testing Pyramid and Front-End Development
 
Introduction to testing in Rails
Introduction to testing in RailsIntroduction to testing in Rails
Introduction to testing in Rails
 
Typescript barcelona
Typescript barcelonaTypescript barcelona
Typescript barcelona
 
Write codeforhumans
Write codeforhumansWrite codeforhumans
Write codeforhumans
 
Javascript unit testing, yes we can e big
Javascript unit testing, yes we can   e bigJavascript unit testing, yes we can   e big
Javascript unit testing, yes we can e big
 
Unit Testing and Coverage for AngularJS
Unit Testing and Coverage for AngularJSUnit Testing and Coverage for AngularJS
Unit Testing and Coverage for AngularJS
 
Test Coverage in Rails
Test Coverage in RailsTest Coverage in Rails
Test Coverage in Rails
 

Recently uploaded

2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf
Łukasz Chruściel
 
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
mz5nrf0n
 
LORRAINE ANDREI_LEQUIGAN_HOW TO USE WHATSAPP.pptx
LORRAINE ANDREI_LEQUIGAN_HOW TO USE WHATSAPP.pptxLORRAINE ANDREI_LEQUIGAN_HOW TO USE WHATSAPP.pptx
LORRAINE ANDREI_LEQUIGAN_HOW TO USE WHATSAPP.pptx
lorraineandreiamcidl
 
GraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph TechnologyGraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph Technology
Neo4j
 
Energy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina JonuziEnergy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina Jonuzi
Green Software Development
 
socradar-q1-2024-aviation-industry-report.pdf
socradar-q1-2024-aviation-industry-report.pdfsocradar-q1-2024-aviation-industry-report.pdf
socradar-q1-2024-aviation-industry-report.pdf
SOCRadar
 
SMS API Integration in Saudi Arabia| Best SMS API Service
SMS API Integration in Saudi Arabia| Best SMS API ServiceSMS API Integration in Saudi Arabia| Best SMS API Service
SMS API Integration in Saudi Arabia| Best SMS API Service
Yara Milbes
 
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CDKuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
rodomar2
 
Unveiling the Advantages of Agile Software Development.pdf
Unveiling the Advantages of Agile Software Development.pdfUnveiling the Advantages of Agile Software Development.pdf
Unveiling the Advantages of Agile Software Development.pdf
brainerhub1
 
SWEBOK and Education at FUSE Okinawa 2024
SWEBOK and Education at FUSE Okinawa 2024SWEBOK and Education at FUSE Okinawa 2024
SWEBOK and Education at FUSE Okinawa 2024
Hironori Washizaki
 
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Crescat
 
openEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain SecurityopenEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain Security
Shane Coughlan
 
E-commerce Application Development Company.pdf
E-commerce Application Development Company.pdfE-commerce Application Development Company.pdf
E-commerce Application Development Company.pdf
Hornet Dynamics
 
DDS-Security 1.2 - What's New? Stronger security for long-running systems
DDS-Security 1.2 - What's New? Stronger security for long-running systemsDDS-Security 1.2 - What's New? Stronger security for long-running systems
DDS-Security 1.2 - What's New? Stronger security for long-running systems
Gerardo Pardo-Castellote
 
Fundamentals of Programming and Language Processors
Fundamentals of Programming and Language ProcessorsFundamentals of Programming and Language Processors
Fundamentals of Programming and Language Processors
Rakesh Kumar R
 
Measures in SQL (SIGMOD 2024, Santiago, Chile)
Measures in SQL (SIGMOD 2024, Santiago, Chile)Measures in SQL (SIGMOD 2024, Santiago, Chile)
Measures in SQL (SIGMOD 2024, Santiago, Chile)
Julian Hyde
 
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOMLORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
lorraineandreiamcidl
 
A Study of Variable-Role-based Feature Enrichment in Neural Models of Code
A Study of Variable-Role-based Feature Enrichment in Neural Models of CodeA Study of Variable-Role-based Feature Enrichment in Neural Models of Code
A Study of Variable-Role-based Feature Enrichment in Neural Models of Code
Aftab Hussain
 
Transform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR SolutionsTransform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR Solutions
TheSMSPoint
 
Oracle Database 19c New Features for DBAs and Developers.pptx
Oracle Database 19c New Features for DBAs and Developers.pptxOracle Database 19c New Features for DBAs and Developers.pptx
Oracle Database 19c New Features for DBAs and Developers.pptx
Remote DBA Services
 

Recently uploaded (20)

2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf
 
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
 
LORRAINE ANDREI_LEQUIGAN_HOW TO USE WHATSAPP.pptx
LORRAINE ANDREI_LEQUIGAN_HOW TO USE WHATSAPP.pptxLORRAINE ANDREI_LEQUIGAN_HOW TO USE WHATSAPP.pptx
LORRAINE ANDREI_LEQUIGAN_HOW TO USE WHATSAPP.pptx
 
GraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph TechnologyGraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph Technology
 
Energy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina JonuziEnergy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina Jonuzi
 
socradar-q1-2024-aviation-industry-report.pdf
socradar-q1-2024-aviation-industry-report.pdfsocradar-q1-2024-aviation-industry-report.pdf
socradar-q1-2024-aviation-industry-report.pdf
 
SMS API Integration in Saudi Arabia| Best SMS API Service
SMS API Integration in Saudi Arabia| Best SMS API ServiceSMS API Integration in Saudi Arabia| Best SMS API Service
SMS API Integration in Saudi Arabia| Best SMS API Service
 
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CDKuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
 
Unveiling the Advantages of Agile Software Development.pdf
Unveiling the Advantages of Agile Software Development.pdfUnveiling the Advantages of Agile Software Development.pdf
Unveiling the Advantages of Agile Software Development.pdf
 
SWEBOK and Education at FUSE Okinawa 2024
SWEBOK and Education at FUSE Okinawa 2024SWEBOK and Education at FUSE Okinawa 2024
SWEBOK and Education at FUSE Okinawa 2024
 
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
 
openEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain SecurityopenEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain Security
 
E-commerce Application Development Company.pdf
E-commerce Application Development Company.pdfE-commerce Application Development Company.pdf
E-commerce Application Development Company.pdf
 
DDS-Security 1.2 - What's New? Stronger security for long-running systems
DDS-Security 1.2 - What's New? Stronger security for long-running systemsDDS-Security 1.2 - What's New? Stronger security for long-running systems
DDS-Security 1.2 - What's New? Stronger security for long-running systems
 
Fundamentals of Programming and Language Processors
Fundamentals of Programming and Language ProcessorsFundamentals of Programming and Language Processors
Fundamentals of Programming and Language Processors
 
Measures in SQL (SIGMOD 2024, Santiago, Chile)
Measures in SQL (SIGMOD 2024, Santiago, Chile)Measures in SQL (SIGMOD 2024, Santiago, Chile)
Measures in SQL (SIGMOD 2024, Santiago, Chile)
 
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOMLORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
 
A Study of Variable-Role-based Feature Enrichment in Neural Models of Code
A Study of Variable-Role-based Feature Enrichment in Neural Models of CodeA Study of Variable-Role-based Feature Enrichment in Neural Models of Code
A Study of Variable-Role-based Feature Enrichment in Neural Models of Code
 
Transform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR SolutionsTransform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR Solutions
 
Oracle Database 19c New Features for DBAs and Developers.pptx
Oracle Database 19c New Features for DBAs and Developers.pptxOracle Database 19c New Features for DBAs and Developers.pptx
Oracle Database 19c New Features for DBAs and Developers.pptx
 

TDD & BDD

  • 2. What is TDD and BDD ?
  • 4. Test Driven Development When I first heard about TDD, the idea seemed to be pretty simple. Just by doing a little word swizzling, obviously TDD is when you have tests that drive your software development. If we were to unpack the definition of TDD a bit more, we'd see that it is usually broken up into five different stages: 1. First the developer writes some tests. 2. The developer then runs those tests and (obviously) they fail because none of those features are actually implemented. 3. Next the developer actually implements those tests in code. 4. If the developer writes his code well, then the in next stage he will see his tests pass.
  • 7. BDD BDD is meant to eliminate issues that TDD might cause. In contrast to TDD, BDD is when we write behavior & specification that then drives our software development. Behavior & specification might seem awfully similar to tests but the difference is very subtle and important.
  • 8. Example #Testing for our User class describe User do context 'with admin privileges' do before :each do @admin = Admin.get(1) end it 'should exist' do expect(@admin).not_to be_nil end it 'should have a name' do expect(@admin.name).not_to be_falsy end end #...
  • 9. Example for TDD and BDD approach
  • 10. var assert = require('assert'), factorial = require('../index');suite('Test', function (){ setup(function (){ // Create any objects that we might need }); suite('#factorial()', function (){ test('equals 1 for sets of zero length', function (){ assert.equal(1, factorial(0)); }); test('equals 1 for sets of length one', function (){ assert.equal(1, factorial(1)); }); test('equals 2 for sets of length two', function (){ assert.equal(2, factorial(2)); }); test('equals 6 for sets of length three', function (){ assert.equal(6, factorial(3)); }); });});
  • 11. var assert = require('assert'), factorial = require('../index');describe('Test', function (){ before(function(){ // Stuff to do before the tests, like imports, what not }); describe('#factorial()', function (){ it('should return 1 when given 0', function (){ factorial(0).should.equal(1); }); it('should return 1 when given 1', function (){ factorial(1).should.equal(1); }); it('should return 2 when given 2', function (){ factorial(2).should.equal(2); }); it('should return 6 when given 3', function (){ factorial(3).should.equal(6); }); });
  • 12. If you have seen the previous example then you can find it out that the first example for the TDD because inside the developer only checking the value of the method But if you have observed the second code then you will find test are more focus on the behaviour.
  • 13.
  • 15. 1) By simply running your rails test you can ensure your code adheres to the desired functionality even after some major code refactoring. 2) Your application response without having to test it through your browser 3) You can easily upgrade your rails application
  • 16. Levels of Testing ● Unit Tests ● Integration Tests ● Acceptance Tests
  • 17.
  • 18.
  • 20. $ ls -F test
  • 21. controllers/ helpers/ mailers/ test_helper.rb fixtures/ integration/ models/
  • 22. Unit Test??? $ rails new TestingTime $rails generate scaffold profile title:string body:text $ rake test test/models/profile_test.rb
  • 23. require 'test_helper' class ProfileTest < ActiveSupport::TestCase test "the truth" do assert true end test "should not have Profile with title" do profile = Profile.new assert_not profile.save # save the title without title end test "should not have profile without body" do profile = Profile.new profile.title = 'Arvind' assert_not profile.save # save the body without title end end class Profile < ActiveRecord::Base class Post < ActiveRecord::Base validates :title, :body, presence: true validates :title, :body, presence: true end end $ rake test test/models/post_test.rb
  • 24. Controllers ?? Testing the various actions of a single controller is called writing functional tests for that controller. Controllers handle the incoming web requests to your application and eventually respond with a rendered view.
  • 25. require 'test_helper' class ProfilerofileControllerTest < ActionController::TestCase setup do @rofileprofile = rofilesprofile(:one) end test "should get index" do get :index assert_response :success assert_not_nil assigns(:profile) end test "should get new" do get :new assert_response :success end test "should create rofileprofile" do assert_difference('Profilerofile.count') do post :create, profile: {title: @profrofile.title, body: @profile.body} end assert_redirected_to profile_path(assigns(:profile)) assert_equal 'Profile was successfully created.', flash[:notice] end
  • 26. #run all the test case which are inside test $ rake test test i
  • 27. What to include in your functional test ->Web request successful -> User redirect to the right place -> User successfully authenticated -> Correct object stored in the response template - > Appropriate message displayed
  • 28. A Last question for all What is the use of integration folder in testing what we put on that ?? ????