You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
122 lines
5.0 KiB
122 lines
5.0 KiB
11 months ago
|
<!DOCTYPE html>
|
||
|
<html lang="en">
|
||
|
<head>
|
||
|
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||
|
<meta http-equiv="content-type" content="text/html; charset=utf-8">
|
||
|
|
||
|
<!-- Enable responsiveness on mobile devices-->
|
||
|
<!-- viewport-fit=cover is to support iPhone X rounded corners and notch in landscape-->
|
||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1, viewport-fit=cover">
|
||
|
|
||
|
<title>Julio Biason .Me 4.3</title>
|
||
|
|
||
|
<!-- CSS -->
|
||
|
<link rel="stylesheet" href="https://blog.juliobiason.me/print.css" media="print">
|
||
|
<link rel="stylesheet" href="https://blog.juliobiason.me/poole.css">
|
||
|
<link rel="stylesheet" href="https://blog.juliobiason.me/hyde.css">
|
||
|
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=PT+Sans:400,400italic,700|Abril+Fatface">
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
</head>
|
||
|
|
||
|
<body class=" ">
|
||
|
|
||
|
<div class="sidebar">
|
||
|
<div class="container sidebar-sticky">
|
||
|
<div class="sidebar-about">
|
||
|
|
||
|
<a href="https://blog.juliobiason.me"><h1>Julio Biason .Me 4.3</h1></a>
|
||
|
|
||
|
<p class="lead">Old school dev living in a 2.0 dev world</p>
|
||
|
|
||
|
|
||
|
</div>
|
||
|
|
||
|
<ul class="sidebar-nav">
|
||
|
|
||
|
|
||
|
<li class="sidebar-nav-item"><a href="/">English</a></li>
|
||
|
|
||
|
<li class="sidebar-nav-item"><a href="/pt">Português</a></li>
|
||
|
|
||
|
<li class="sidebar-nav-item"><a href="/tags">Tags (EN)</a></li>
|
||
|
|
||
|
<li class="sidebar-nav-item"><a href="/pt/tags">Tags (PT)</a></li>
|
||
|
|
||
|
|
||
|
</ul>
|
||
|
</div>
|
||
|
</div>
|
||
|
|
||
|
|
||
|
<div class="content container">
|
||
|
|
||
|
<div class="post">
|
||
|
<h1 class="post-title">Code is a Book, Unit Tests are Spellcheckers</h1>
|
||
|
<span class="post-date">
|
||
|
2020-02-14
|
||
|
|
||
|
<a href="https://blog.juliobiason.me/tags/unit-tests/">#unit tests</a>
|
||
|
|
||
|
<a href="https://blog.juliobiason.me/tags/testing/">#testing</a>
|
||
|
|
||
|
<a href="https://blog.juliobiason.me/tags/integration-tests/">#integration tests</a>
|
||
|
|
||
|
<a href="https://blog.juliobiason.me/tags/books/">#books</a>
|
||
|
|
||
|
<a href="https://blog.juliobiason.me/tags/code/">#code</a>
|
||
|
|
||
|
</span>
|
||
|
<p>If we use an analogy for code as being the words in a book and the system
|
||
|
being built as the whole book, then what are unit tests?</p>
|
||
|
<span id="continue-reading"></span>
|
||
|
<p>I just found this analogy pretty good<sup class="footnote-reference"><a href="#1">1</a></sup>: You can to think about your code
|
||
|
as a book: Each module is a chapter, each class is a paragraph and each
|
||
|
function is a sentence.</p>
|
||
|
<p>In that analogy, were would unit tests sit?</p>
|
||
|
<p>To me, the unit tests are like spell checkers -- or, at least, the more modern
|
||
|
ones: Are you writing the proper words? Are your sentences grammatically
|
||
|
correct? The spell checker will take care of this.</p>
|
||
|
<p>But there is one thing that the spell checker won't do: make sure the chapter
|
||
|
makes sense in the whole context of the book. Escaping the analogy for a
|
||
|
moment, let me ask you this: Have you read "Les Misérables"? I did, and there
|
||
|
is one chapter in the middle of the book in which Victor Hugo discuss the
|
||
|
Battle of Waterloo. Although it makes sense in the historical point of the
|
||
|
story of Les Misérables, it makes absolutely no sense in the general story
|
||
|
itself -- no matter how well punctuate, correct in spelling and grammar it may
|
||
|
be.</p>
|
||
|
<p>This is a huge failure of unit tests: They don't see the whole. The whole is
|
||
|
given by reviewers of a book and integration tests of a system. Jumping back
|
||
|
to the analogy, when you have your integration tests defined by the system
|
||
|
requisites, anything that isn't being covered is a chapter that doesn't make
|
||
|
sense in the whole of the book.</p>
|
||
|
<p>In the long run, as writers will remember the times the spell checker
|
||
|
pointed a word was spelled wrong or a verb was in the wrong tense and, thus,
|
||
|
make it pop less and less, so does unit tests: In the long run, the ROI<sup class="footnote-reference"><a href="#2">2</a></sup> of
|
||
|
unit tests tend to go down, while the integration tests -- the ones that check
|
||
|
if the "chapter" makes sense in the story being told by the "book" -- tend to
|
||
|
go up.</p>
|
||
|
<p>And I just found the analogy so good for the way I see those two test
|
||
|
methodologies.</p>
|
||
|
<hr />
|
||
|
<div class="footnote-definition" id="1"><sup class="footnote-definition-label">1</sup>
|
||
|
<p>... but I lost the source of it. :(</p>
|
||
|
</div>
|
||
|
<div class="footnote-definition" id="2"><sup class="footnote-definition-label">2</sup>
|
||
|
<p>"Return Of Investment"</p>
|
||
|
</div>
|
||
|
|
||
|
</div>
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
</div>
|
||
|
|
||
|
</body>
|
||
|
|
||
|
</html>
|