More Related Content Similar to The hitchhicker’s guide to unit testing (20) The hitchhicker’s guide to unit testing11. And
again
again
void
testMyTest()
{
Obj
obj
=
new
Obj();
//
10
lignes
of
things
assertEquals(…);
}
18. One
test
One
(english)
sentence
Behavior
tesZng,
don’t
test,
do
describe
23. 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”
24. 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”
25. 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”
26. 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”
32. &&
++
!=
>
…
||
-‐-‐
==
<
…
Mutate
it
33. if(a
&&
b)
{
i++;
}
else
{
i-‐-‐;
}
if(a || b) {
i++;
} else {
i--;
}
if(a && b) {
i--;
} else {
i--;
}
Mutate
it
38. 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
42. How
to
test
string
concatenaZon
?
assert(
("ta"
+
"a")
==
"taa"
)
43. How
to
test
string
concatenaZon
?
assert(
("ta"
+
"a")
==
"taa"
)
assert(
("ta"
+
"b")
==
"tab"
)
44. How
to
test
string
concatenaZon
?
assert(
("ta"
+
"a")
==
"taa"
)
assert(
("ta"
+
"b")
==
"tab"
)
…
45. How
to
test
string
concatenaZon
?
assert(
("ta"
+
"a")
==
"taa"
)
assert(
("ta"
+
"b")
==
"tab"
)
assert(
("ta"
+
"z")
==
"taz"
)
…
46. How
to
test
string
concatenaZon
?
assert(
("ta"
+
"a")
==
"taa"
)
assert(
("ta"
+
"b")
==
"tab"
)
assert(
("ta"
+
"z")
==
"taz"
)
…
But
boring
48. val
n:
Int
val
k:
Int
(n
==
2k
||
n
==
2k
+
1)
==
true
(n
%
2
==
0
||
n
%
2
==
1)
==
true
In
code
49. 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
52. Behavior
tesZng
Every
day
MutaZon
tesZng
CriZcal
code
Property
tesZng
à
CriZcal
code
Share
and
Enjoy
53. So
Long,
and
Thanks
for
All
the
Fish
Rémy-‐Christophe
Schermesser
@el_picador
54. Rémy-‐Christophe
Schermesser
@el_picador
Behavior
tesZng
Rspec
(ruby)
Jasmine
(javascript)
MutaZon
tesZng
Javalanche
(java)
Mutant
(ruby)
Property
tesZng
ScalaCheck
(scala)
QuickCheck
(haskell)
MrProper
(ruby)