157 lines
4.7 KiB
HTML
157 lines
4.7 KiB
HTML
|
|
<html>
|
||
|
|
<head>
|
||
|
|
<link rel="stylesheet" href="css/reveal.css">
|
||
|
|
<link rel="stylesheet" href="css/theme/serif.css">
|
||
|
|
</head>
|
||
|
|
<body>
|
||
|
|
<div class="reveal">
|
||
|
|
<div class="slides">
|
||
|
|
<section>
|
||
|
|
<h2>Property based testing 101</h2>
|
||
|
|
<aside class="notes">
|
||
|
|
</aside>
|
||
|
|
</section>
|
||
|
|
<section>
|
||
|
|
<h2>Yet another testing talk?</h2>
|
||
|
|
<aside class="notes">
|
||
|
|
</aside>
|
||
|
|
</section>
|
||
|
|
<section>
|
||
|
|
<h2>This talk is different</h2>
|
||
|
|
<aside class="notes">
|
||
|
|
</aside>
|
||
|
|
</section>
|
||
|
|
<section>
|
||
|
|
<h2>People already said a lot about testing</h2>
|
||
|
|
<aside class="notes">
|
||
|
|
Uncle Bob
|
||
|
|
Sandi Metz
|
||
|
|
</aside>
|
||
|
|
</section>
|
||
|
|
<section>
|
||
|
|
<h2>Why do we test?</h2>
|
||
|
|
<aside class="notes">
|
||
|
|
Confidence<br />
|
||
|
|
UTs are great for regression, quick to write <br />
|
||
|
|
Non corner cases
|
||
|
|
</aside>
|
||
|
|
</section>
|
||
|
|
<section>
|
||
|
|
<h2>Property Based Testing success stories</h2>
|
||
|
|
<ul>
|
||
|
|
<li>Riak</li>
|
||
|
|
<li>Level DB</li>
|
||
|
|
<li>Volvo</li>
|
||
|
|
</ul>
|
||
|
|
<aside class="notes">
|
||
|
|
Riak - few calls to produce errors <br />
|
||
|
|
Level DB - ~20 calls to make some errors <br />
|
||
|
|
Volvo - errors in protocol, 200+ errors <br />
|
||
|
|
</aside>
|
||
|
|
</section>
|
||
|
|
<section>
|
||
|
|
<h2>How many tests are enough?</h2>
|
||
|
|
<aside class="notes">
|
||
|
|
How many regular tests would we need to find LevelDB example? <br />
|
||
|
|
LevelDB - only 2 functions - 2^n calls = 2^n unit tests
|
||
|
|
</aside>
|
||
|
|
</section>
|
||
|
|
<section>
|
||
|
|
<h2>Unit Testing vs Property Based Testing</h2>
|
||
|
|
<ul>
|
||
|
|
<li>What does unit, integration, system etc tests have in common?</li>
|
||
|
|
<li>Example based vs Property based</li>
|
||
|
|
</ul>
|
||
|
|
<aside class="notes">
|
||
|
|
</aside>
|
||
|
|
</section>
|
||
|
|
<section>
|
||
|
|
<h2>What is property?</h2>
|
||
|
|
<ul>
|
||
|
|
<li>length(list) == length(reverse(list))</li>
|
||
|
|
<li> assert reverse(reverse(list)) equals list</li>
|
||
|
|
<li> assert reverse(list)[k] equals list[length(list)-k]</li>
|
||
|
|
</ul>
|
||
|
|
<aside class="notes">
|
||
|
|
</aside>
|
||
|
|
</section>
|
||
|
|
<section>
|
||
|
|
<h2>What else?</h2>
|
||
|
|
<ul>
|
||
|
|
<li>Generator</li>
|
||
|
|
<li>Shrinking</li>
|
||
|
|
</ul>
|
||
|
|
<aside class="notes">
|
||
|
|
</aside>
|
||
|
|
</section>
|
||
|
|
<section>
|
||
|
|
<h2>Generator</h2>
|
||
|
|
<h4>list <- <b>generate_list</b></h4>
|
||
|
|
<ul>
|
||
|
|
<li>[1]</li>
|
||
|
|
<li>[-1, 3, 5]</li>
|
||
|
|
<li>[-50, -10, 3, 14, 25, 100]</li>
|
||
|
|
<li>etc</li>
|
||
|
|
</ul>
|
||
|
|
</section>
|
||
|
|
<section>
|
||
|
|
<h2>Shrinking</h2>
|
||
|
|
<h4> Let's assume reverse function that will remove element <i>42</i> if found</i></h4>
|
||
|
|
<ul>
|
||
|
|
<li>Failed: [-10, -8, ..., 42, ... 87, 100]</li>
|
||
|
|
<li>Shrinking...</li>
|
||
|
|
<li>Minimal failing test case: [42]</li>
|
||
|
|
</ul>
|
||
|
|
</section>
|
||
|
|
<section>
|
||
|
|
<h2>Sample test</h2>
|
||
|
|
<ul>
|
||
|
|
<li>list <- generate_list</li>
|
||
|
|
<li>k <- generate_int(0, length(list)-1)</li>
|
||
|
|
<li> assert length(reverse(list)) equals length(list)</li>
|
||
|
|
<li> assert reverse(reverse(list)) equals list</li>
|
||
|
|
<li> assert reverse(list)[k] equals list[length(list)-k]</li>
|
||
|
|
</ul>
|
||
|
|
</section>
|
||
|
|
<section>
|
||
|
|
<h2>Why should I care?</h2>
|
||
|
|
<aside class="notes">
|
||
|
|
Even ruby, found some python stuff. Great for testing validation in oop
|
||
|
|
</aside>
|
||
|
|
</section>
|
||
|
|
<section>
|
||
|
|
<h2>Bad stuff?</h2>
|
||
|
|
<ul>
|
||
|
|
<li>Time consuming</li>
|
||
|
|
<li>Learning curve</li>
|
||
|
|
</ul>
|
||
|
|
<aside class="notes">
|
||
|
|
Takes time to write and run. Example with reverse - simple but need to find a lot of things.
|
||
|
|
</aside>
|
||
|
|
</section>
|
||
|
|
<section>
|
||
|
|
<h3>Thank you & questions</h3>
|
||
|
|
<p>Lukasz Skotarek</p>
|
||
|
|
<p>@dreat_ on Twitter</p>
|
||
|
|
<p>dreat on Elixir/3cityIt/HS Slack</p>
|
||
|
|
<p>mail: contact@dreat.info</p>
|
||
|
|
</section>
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
<script src="lib/js/head.min.js"></script>
|
||
|
|
<script src="js\reveal.js"></script>
|
||
|
|
<script>
|
||
|
|
Reveal.initialize(
|
||
|
|
{
|
||
|
|
controls: true,
|
||
|
|
progress: true,
|
||
|
|
|
||
|
|
dependencies: [
|
||
|
|
{ src: 'plugin/notes/notes.js', async: true }
|
||
|
|
]
|
||
|
|
}
|
||
|
|
);
|
||
|
|
</script>
|
||
|
|
</body>
|
||
|
|
</html>
|