The hitchhicker’s guide to unit testing
-
Upload
remy-christophe-schermesser -
Category
Technology
-
view
640 -
download
1
description
Transcript of The hitchhicker’s guide to unit testing
describe CompaniesController do describe "POST create" do context "when recruiter
signed_in with no company" do … end end end
describe CompaniesController do describe "POST create" do context "when recruiter
signed_in with no company" do … end end end
describe CompaniesController do describe "POST create" do context "when recruiter
signed_in with no company an email is sent" do
… end end end
let!(:recruiter) { login_recruiter create(:recruiter, company_id: nil) } context "when good params" do let(:params) { … } it { expect { post :create, params }.to change(Company, :count).by 1 } it { expect { post :create, params }.to change(Ac1onMailer::Base.deliveries, :count).by 2 } end
“When recruiter signed_in with no company”
let!(:recruiter) { login_recruiter create(:recruiter, company_id: nil) } context "when good params" do let(:params) { … } it { expect { post :create, params }.to change(Company, :count).by 1 } it { expect { post :create, params }.to change(Ac1onMailer::Base.deliveries, :count).by 2 } end
“When recruiter signed_in with no company”
let!(:recruiter) { login_recruiter create(:recruiter, company_id: nil) } context "when good params" do let(:params) { … } it { expect { post :create, params }.to change(Company, :count).by 1 } it { expect { post :create, params }.to change(Ac1onMailer::Base.deliveries, :count).by 2 } end
“When recruiter signed_in with no company”
let!(:recruiter) { login_recruiter create(:recruiter, company_id: nil) } context "when good params" do let(:params) { … } it { expect { post :create, params }.to change(Company, :count).by 1 } it { expect { post :create, params }.to change(Ac1onMailer::Base.deliveries, :count).by 2 } end
“When recruiter signed_in with no company”
if(a && b) { i++; } else { i-‐-‐; }
if(a || b) { i++; } else { i--; }
if(a && b) { i--; } else { i--; }
Mutate it
Coverage data Equivalent mutant if(index >= 10) break and if(index == 10) break
Selec1ve muta1on
Parallel execu1on Choose your mutants wisely
Using code coverage to reduce the tests to run
Speed-‐up
The right tool
How to test string concatenaZon ?
assert( ("ta" + "a") == "taa" ) assert( ("ta" + "b") == "tab" )
assert( ("ta" + "z") == "taz" )
…
How to test string concatenaZon ?
assert( ("ta" + "a") == "taa" ) assert( ("ta" + "b") == "tab" )
assert( ("ta" + "z") == "taz" )
…
But boring
val a: String val b: String ((a+b) endsWith b) == true ((a+b) startsWith a) == true (a+b).length == a.length + b.length
String concatenaZon properZes
List[Int] => isPalindrome(list) (list.reverse == list) ==> isPalindrome(list) (list.reverse != list) ==> !isPalindrome(list)
Limits
Behavior tesZng Every day
MutaZon tesZng CriZcal code
Property tesZng à CriZcal code
Share and Enjoy