Skip to content

Commit 9d28369

Browse files
committed
Moving key points to reference.md
1 parent 4de5ac3 commit 9d28369

24 files changed

+225
-226
lines changed

01-basics.html

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
<div class="row">
2828
<div class="col-md-10 col-md-offset-1">
2929
<a href="index.html"><h1 class="title">Testing</h1></a>
30-
<h2 class="subtitle">Basics of testing</h2>
30+
<h2 class="subtitle">Basics of Testing</h2>
3131
<section class="objectives panel panel-warning">
3232
<div class="panel-heading">
3333
<h2><span class="glyphicon glyphicon-certificate"></span>Learning Objectives</h2>
@@ -46,8 +46,11 @@ <h2><span class="glyphicon glyphicon-certificate"></span>Learning Objectives</h2
4646
<li>The act of writing tests can help clarify how the software should be perform when you are done.</li>
4747
<li>In fact, starting to write the tests <em>before</em> you even write the software might be advisable. (Such a practice is called <em>test-driven development</em>, which we will discuss in greater detail <a href="09-tdd.html">later in the lesson</a>.)</li>
4848
</ul>
49-
<blockquote>
50-
<h3>What Kinds of Tests Exist</h3>
49+
<aside class="callout panel panel-info">
50+
<div class="panel-heading">
51+
<h2><span class="glyphicon glyphicon-pushpin"></span>What Kinds of Tests Exist</h2>
52+
</div>
53+
<div class="panel-body">
5154
<p>There are many ways to test software, such as:</p>
5255
<ul>
5356
<li>Assertions</li>
@@ -56,22 +59,12 @@ <h3>What Kinds of Tests Exist</h3>
5659
<li>Regresson Tests</li>
5760
<li>Integration Tests</li>
5861
</ul>
59-
</blockquote>
62+
</div>
63+
</aside>
6064
<p><em>Exceptions and Assertions</em>: While writing code, <code>exceptions</code> and <code>assertions</code> can be added to sound an alarm as runtime problems come up. These kinds of tests, are embedded in the software iteself and handle, as their name implies, exceptional cases rather than the norm.</p>
6165
<p><em>Unit Tests</em>: Unit tests investigate the behavior of units of code (such as functions, classes, or data structures). By validating each software unit across the valid range of its input and output parameters, tracking down unexpected behavior that may appear when the units are combined is made vastly simpler.</p>
6266
<p><em>Regression Tests</em>: Regression tests defend against new bugs, or regressions, which might appear due to new software and updates.</p>
6367
<p><em>Integration Tests</em>: Integration tests check that various pieces of the software work together as expected.</p>
64-
<blockquote>
65-
<h2>Key Points</h2>
66-
<ul>
67-
<li>Tests compare that the result observed from running code is the same as what was expected ahead of time.</li>
68-
<li>Tests should be written at the same time as the code they are testing is written.</li>
69-
<li>Assertions and exceptions are like alarm systems embedded in the software, guarding against exceptional bahavior.</li>
70-
<li>Unit tests try to test the smallest pieces of code possible, usually functions and methods.</li>
71-
<li>Integration tests make sure that code units work together properly.</li>
72-
<li>Regression tests ensure that everything works the same today as it did yesterday.</li>
73-
</ul>
74-
</blockquote>
7568
</div>
7669
</div>
7770
</article>

01-basics.md

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
layout: page
33
title: Testing
4-
subtitle: Basics of testing
4+
subtitle: Basics of Testing
55
minutes: 5
66
---
77
> ## Learning Objectives {.objectives}
@@ -24,7 +24,8 @@ This is analogous to experiment design in the experimental science world:
2424
might be advisable. (Such a practice is called _test-driven development_,
2525
which we will discuss in greater detail [later in the lesson](09-tdd.html).)
2626

27-
> ### What Kinds of Tests Exist
27+
> ## What Kinds of Tests Exist {.callout}
28+
>
2829
> There are many ways to test software, such as:
2930
>
3031
> - Assertions
@@ -49,14 +50,3 @@ which might appear due to new software and updates.
4950

5051
*Integration Tests*: Integration tests check that various pieces of the
5152
software work together as expected.
52-
53-
54-
> ## Key Points {.keypoints}
55-
>
56-
> - Tests compare that the result observed from running code is the same as what was expected ahead of time.
57-
> - Tests should be written at the same time as the code they are testing is written.
58-
> - Assertions and exceptions are like alarm systems embedded in the software, guarding against exceptional bahavior.
59-
> - Unit tests try to test the smallest pieces of code possible, usually functions and methods.
60-
> - Integration tests make sure that code units work together properly.
61-
> - Regression tests ensure that everything works the same today as it did yesterday.
62-

02-assertions.html

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ <h2><span class="glyphicon glyphicon-certificate"></span>Learning Objectives</h2
5555
<p>Also, input checking may require decending a rabbit hole of exceptional cases. What happens when the input provided to the mean function is a string, rather than a list of numbers?</p>
5656
<section class="challenge panel panel-success">
5757
<div class="panel-heading">
58-
<h2><span class="glyphicon glyphicon-pencil"></span>Challenge Insert an Assertion</h2>
58+
<h2><span class="glyphicon glyphicon-pencil"></span>Insert an Assertion</h2>
5959
</div>
6060
<div class="panel-body">
6161
<ol style="list-style-type: decimal">
@@ -73,7 +73,7 @@ <h2><span class="glyphicon glyphicon-pencil"></span>Challenge Insert an Assertio
7373
<p>Assertions are also helpful for catching abnormal behaviors, such as those that arise with floating point arithmetic.</p>
7474
<section class="challenge panel panel-success">
7575
<div class="panel-heading">
76-
<h2><span class="glyphicon glyphicon-pencil"></span>Challenge: Almost Equal</h2>
76+
<h2><span class="glyphicon glyphicon-pencil"></span>Almost Equal</h2>
7777
</div>
7878
<div class="panel-body">
7979
<p>Assertions are also helpful for catching abnormal behaviors, such as those that arise with floating point arithmetic. Using the assert keyword, how could you test whether some value is almost the same as another value?</p>
@@ -90,24 +90,13 @@ <h2><span class="glyphicon glyphicon-pencil"></span>Challenge: Almost Equal</h2>
9090
</div>
9191
</section>
9292
<p>To help with situations such as those above, there are classes of more helpful assertions that we will use often in later parts of this testing lesson as the building blocks of our tests. The nose testing package contains many of them.</p>
93-
<h3 id="nose">Nose</h3>
93+
<h2 id="nose">Nose</h2>
9494
<p>The nose testing framework has built-in assertion types implementing <code>assert_almost_equal</code>, <code>assert_true</code>, <code>assert_false</code>, <code>assert_raises</code>, <code>assert_is_instance</code>, and others.</p>
9595
<pre class="sourceCode python"><code class="sourceCode python"><span class="ch">from</span> nose.tools <span class="ch">import</span> assert_almost_equal
9696
<span class="ch">from</span> mynum <span class="ch">import</span> a
9797
assert_almost_equal(a, <span class="dv">2</span>, places=<span class="dv">2</span>)
9898
assert_almost_equal(a, <span class="dv">2</span>, delta=<span class="fl">0.003</span>)</code></pre>
9999
<p>These assertions give much more helpful error messages and have much more powerful features than the simple assert keyword. An even more powerful sibling of the assertion is the <em>exception</em>. We’ll learn about those in the next lesson.</p>
100-
<blockquote>
101-
<h2>Key Points</h2>
102-
<ul>
103-
<li>Assertions are one line tests embedded in code.</li>
104-
<li>The <code>assert</code> keyword is used to set an assertion.</li>
105-
<li>Assertions halt execution if the argument is false.</li>
106-
<li>Assertions do nothing if the argument is true.</li>
107-
<li>The <code>nose.tools</code> package provides more informative assertions.</li>
108-
<li>Assertions are the building blocks of tests.</li>
109-
</ul>
110-
</blockquote>
111100
</div>
112101
</div>
113102
</article>

02-assertions.md

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,7 @@ Also, input checking may require decending a rabbit hole of exceptional cases.
4848
What happens when the input provided to the mean function is a string, rather
4949
than a list of numbers?
5050

51-
52-
> ## Challenge Insert an Assertion {.challenge}
53-
>
51+
> ## Insert an Assertion {.challenge}
5452
>
5553
> 1. Open an IPython Notebook
5654
> 2. Create the following function:
@@ -70,7 +68,8 @@ than a list of numbers?
7068
Assertions are also helpful for catching abnormal behaviors, such as those that
7169
arise with floating point arithmetic.
7270
73-
> ## Challenge: Almost Equal {.challenge}
71+
> ## Almost Equal {.challenge}
72+
>
7473
> Assertions are also helpful for catching abnormal behaviors, such as those
7574
> that arise with floating point arithmetic. Using the assert keyword, how could
7675
> you test whether some value is almost the same as another value?
@@ -91,7 +90,7 @@ To help with situations such as those above, there are classes of more helpful
9190
assertions that we will use often in later parts of this testing lesson as the
9291
building blocks of our tests. The nose testing package contains many of them.
9392
94-
### Nose
93+
## Nose
9594
9695
The nose testing framework has built-in assertion types implementing
9796
`assert_almost_equal`, `assert_true`, `assert_false`, `assert_raises`,
@@ -108,13 +107,3 @@ These assertions give much more helpful error messages and have much more
108107
powerful features than the simple assert keyword. An even more powerful sibling
109108
of the assertion is the _exception_. We'll learn about those in the next
110109
lesson.
111-
112-
113-
> ## Key Points {.keypoints}
114-
>
115-
> - Assertions are one line tests embedded in code.
116-
> - The `assert` keyword is used to set an assertion.
117-
> - Assertions halt execution if the argument is false.
118-
> - Assertions do nothing if the argument is true.
119-
> - The `nose.tools` package provides more informative assertions.
120-
> - Assertions are the building blocks of tests.

03-exceptions.html

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ <h2><span class="glyphicon glyphicon-certificate"></span>Learning Objectives</h2
7171
<span class="kw">raise</span> <span class="ot">TypeError</span>(detail.<span class="ot">__str__</span>() + <span class="st">&quot;</span><span class="ch">\n</span><span class="st">&quot;</span> + msg)</code></pre>
7272
<section class="challenge panel panel-success">
7373
<div class="panel-heading">
74-
<h2><span class="glyphicon glyphicon-pencil"></span>Challenge: What Else Can Go Wrong?</h2>
74+
<h2><span class="glyphicon glyphicon-pencil"></span>What Else Can Go Wrong?</h2>
7575
</div>
7676
<div class="panel-body">
7777
<ol style="list-style-type: decimal">
@@ -82,7 +82,7 @@ <h2><span class="glyphicon glyphicon-pencil"></span>Challenge: What Else Can Go
8282
</section>
8383
<section class="challenge panel panel-success">
8484
<div class="panel-heading">
85-
<h2><span class="glyphicon glyphicon-pencil"></span>Challenge: Cause all of the errors</h2>
85+
<h2><span class="glyphicon glyphicon-pencil"></span>Cause All of the Errors</h2>
8686
</div>
8787
<div class="panel-body">
8888
<ul>
@@ -91,14 +91,6 @@ <h2><span class="glyphicon glyphicon-pencil"></span>Challenge: Cause all of the
9191
</div>
9292
</section>
9393
<p>Exceptions have the advantage of being simple to include and powerfully helpful to the user. However, not all behaviors can or should be found with runtime exceptions. Most behaviors should be validated with unit tests.</p>
94-
<blockquote>
95-
<h2>Key Points</h2>
96-
<ul>
97-
<li>Exceptions are effectively specialized runtime tests</li>
98-
<li>Exceptions can be caught and handled with a try-except block</li>
99-
<li>Many built-in Exception types are available</li>
100-
</ul>
101-
</blockquote>
10294
</div>
10395
</div>
10496
</article>

03-exceptions.md

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -71,23 +71,17 @@ def mean(num_list):
7171
raise TypeError(detail.__str__() + "\n" + msg)
7272
~~~
7373

74-
> ## Challenge: What Else Can Go Wrong? {.challenge}
74+
> ## What Else Can Go Wrong? {.challenge}
75+
>
7576
> 1. Think of some other type of exception that could be raised by the try
7677
> block.
7778
> 2. Guard against it by adding an except clause.
7879
79-
> ## Challenge: Cause all of the errors {.challenge}
80+
> ## Cause All of the Errors {.challenge}
8081
>
8182
> - Use the mean function in three different ways, so that you cause each
8283
> exceptional case.
8384
8485
Exceptions have the advantage of being simple to include and powerfully helpful
8586
to the user. However, not all behaviors can or should be found with runtime
8687
exceptions. Most behaviors should be validated with unit tests.
87-
88-
> ## Key Points {.keypoints}
89-
>
90-
> - Exceptions are effectively specialized runtime tests
91-
> - Exceptions can be caught and handled with a try-except block
92-
> - Many built-in Exception types are available
93-

04-units.html

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ <h2 id="unit-tests-are-just-functions">Unit Tests Are Just Functions</h2>
6666
<p>A unit test suite is made up of many tests just like this one. A single implemented function may be tested in numerous ways.</p>
6767
<section class="challenge panel panel-success">
6868
<div class="panel-heading">
69-
<h2><span class="glyphicon glyphicon-pencil"></span>Challenge: Write a File Full of Tests</h2>
69+
<h2><span class="glyphicon glyphicon-pencil"></span>Write a File Full of Tests</h2>
7070
</div>
7171
<div class="panel-body">
7272
<ol style="list-style-type: decimal">
@@ -112,16 +112,6 @@ <h2><span class="glyphicon glyphicon-pencil"></span>Challenge: Write a File Full
112112
</div>
113113
</section>
114114
<p>Well, <strong>that</strong> was tedious.</p>
115-
<blockquote>
116-
<h2>Key Points</h2>
117-
<ul>
118-
<li>Functions are the atomistic unit of software.</li>
119-
<li>Simpler units are easier to test than complex ones.</li>
120-
<li>A single unit test is a function containing assertions.</li>
121-
<li>Such a unit test is run just like any other function.</li>
122-
<li><strong>Running tests one at a time is pretty tedious.</strong> (let’s use a framework instead)</li>
123-
</ul>
124-
</blockquote>
125115
</div>
126116
</div>
127117
</article>

04-units.md

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ be made any simpler logically (you cannot split apart the addition operator) or
2525
practically (a function is self-contained and well defined), then it is a unit.
2626

2727
> ## Functions are Like Paragraphs {.callout}
28+
>
2829
> Recall that humans can only hold a few ideas in our heads at once. Paragraphs
2930
> in books, for example, become unwieldy after a few lines. Functions, generaly,
3031
> shouldn't be longer than paragraphs.
@@ -69,7 +70,8 @@ The test above:
6970
A unit test suite is made up of many tests just like this one. A single
7071
implemented function may be tested in numerous ways.
7172

72-
> ## Challenge: Write a File Full of Tests {.challenge}
73+
> ## Write a File Full of Tests {.challenge}
74+
>
7375
> 1. In a file called `test_mean.py`, implement the following code:
7476
>
7577
> ~~~ {.python}
@@ -113,13 +115,3 @@ implemented function may be tested in numerous ways.
113115
>
114116
115117
Well, **that** was tedious.
116-
117-
> ## Key Points {.keypoints}
118-
>
119-
> - Functions are the atomistic unit of software.
120-
> - Simpler units are easier to test than complex ones.
121-
> - A single unit test is a function containing assertions.
122-
> - Such a unit test is run just like any other function.
123-
> - **Running tests one at a time is pretty tedious.** (let's use a framework
124-
> instead)
125-

05-nose.html

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -110,17 +110,6 @@ <h2><span class="glyphicon glyphicon-pencil"></span>Fix The Failing Code</h2>
110110
</div>
111111
</section>
112112
<p>As we write more code, we would write more tests, and <em>nosetests</em> would produce more dots. Each passing test is a small, satisfying reward for having written quality scientific software. Now that you know how to write tests, let’s go into what can go wrong.</p>
113-
<blockquote>
114-
<h2>Key Points</h2>
115-
<ul>
116-
<li>The <code>nosetests</code> command collects and runs tests starting with <code>Test-</code>, <code>test_</code>, and similar names.</li>
117-
<li><code>.</code> means the test passed</li>
118-
<li><code>F</code> means the test failed</li>
119-
<li><code>E</code> encountered an error</li>
120-
<li><code>K</code> is a known failure</li>
121-
<li><code>S</code> is a purposefully skipped test</li>
122-
</ul>
123-
</blockquote>
124113
</div>
125114
</div>
126115
</article>

05-nose.md

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ will print summary information.
103103

104104

105105
> ## Fix The Failing Code {.challenge}
106+
>
106107
> Without changing the tests, alter the mean.py file from the previous section until it passes.
107108
> When it passes, _nosetests_ will produce results like the following:
108109
>
@@ -121,13 +122,3 @@ As we write more code, we would write more tests, and _nosetests_ would produce
121122
more dots. Each passing test is a small, satisfying reward for having written
122123
quality scientific software. Now that you know how to write tests, let's go
123124
into what can go wrong.
124-
125-
126-
> ## Key Points {.keypoints}
127-
>
128-
> - The `nosetests` command collects and runs tests starting with `Test-`, `test_`, and similar names.
129-
> - `.` means the test passed
130-
> - `F` means the test failed
131-
> - `E` encountered an error
132-
> - `K` is a known failure
133-
> - `S` is a purposefully skipped test

0 commit comments

Comments
 (0)