Can you trust your tests?
-
Upload
vaidas-pilkauskas -
Category
Software
-
view
128 -
download
0
Transcript of Can you trust your tests?
"Program testing can be usedto show the presence of bugs,
but never to show theirabsence!"
- Edsger W. Dijkstra
Linedef foo(arg = true) arg ? "a" : "b"end
expect(foo).to eq "a"
100% line coverage. No test for "b".
Branchdef foo(arg) arg ? "a" : "b"end
expect(foo(true)).to eq "a"expect(foo(false)).to eq "b"
100% branch coverage
Can you trust 100%coverage?
Code coverage can only show what isnot tested100% code coverage for interpretedlanguages is kind of like fullcompilation
Terminology
Applying a mutation to some codecreates a mutant.
If test passes - mutant has survived.If test fails - mutant is killed.
What if mutant survives
Simplify your codeAdd additional tests
TDD - minimal amount of code topass the test
Hunting tips# Avoid literalsposts[0] => posts.first
# Don’t overuse syntactic constructs::User => User
# Don’t pass literal defaultsnum.to_s(10) => num.to_s
Equivalent mutations# Originali = 0while i != 10 do_something i += 1end
# Mutanti = 0while i < 10 do_something i += 1end
How
Mutant uses a pure Ruby parserand an unparser to do its magic.
AST:p Parser::CurrentRuby.parse("2 + 2")# (send# (int 2) :+# (int 2))
Mutations
Literal / primitive and compoundStatement deletionConditionalBinary connective replacementArgument deletion / rename / swapUnary operator exchangeBitwise
Test-Selection$ mutant --include lib --require bar --use rspec Foo::Bar#baz
1. Foo::Bar#baz2. Foo::Bar3. Foo
Summary
Normal code coverage highlightscode that is definitely not testedMutation testing highlights codethat definitely is tested
Pictures
s05 -
s08 -
s15 - s16 - s21 -
http://crazy-monkeeey.deviantart.com/art/Who-watches-the-Watchmen-344523349
http://www.chimpsanctuarynw.org/blog/wp-content/uploads/2009/03/negra-covered-in-pink-blanket-front-room_web_mg_8161.jpg
https://twitter.com/bloerwald/status/448415935926255618http://www.smosh.com/smosh-pit/photos/12-more-bizarre-mutant-animalshttps://tbgsecurity.com/the-history-of-hacking-timeline-of-hacking-
techniques-infographic/