Upload
remy-christophe-schermesser
View
640
Download
1
Embed Size (px)
DESCRIPTION
You already know TDD, your code coverage is almost at 80%, jUnit has no secret for you? But you feel that you could do more with your tests, the tools you use have limitations. Or maybe you're just tired of assertEquals? Don't panic! We will see how you can code tests. We will look upon: - Mutation Testing - BDD, Behaviour Driven Development - Property Testing
Citation preview
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