<div class="xblock xblock-public_view xblock-public_view-vertical" data-course-id="course-v1:MITx+6.005.1x+3T2016" data-graded="True" data-init="VerticalStudentView" data-request-token="9dc66f4a223711f0978c16ffcd2b1d4d" data-runtime-version="1" data-block-type="vertical" data-usage-id="block-v1:MITx+6.005.1x+3T2016+type@vertical+block@Reading_3_Objectives" data-runtime-class="LmsRuntime" data-has-score="False">
<h2 class="hd hd-2 unit-title">Reading 3 Objectives</h2>
<div class="vert-mod">
<div class="vert vert-0" data-id="block-v1:MITx+6.005.1x+3T2016+type@video+block@video_c05f1e35755e">
<div class="xblock xblock-public_view xblock-public_view-video xmodule_display xmodule_VideoBlock" data-course-id="course-v1:MITx+6.005.1x+3T2016" data-graded="True" data-init="XBlockToXModuleShim" data-request-token="9dc66f4a223711f0978c16ffcd2b1d4d" data-runtime-version="1" data-block-type="video" data-usage-id="block-v1:MITx+6.005.1x+3T2016+type@video+block@video_c05f1e35755e" data-runtime-class="LmsRuntime" data-has-score="False">
<script type="json/xblock-args" class="xblock-json-init-args">
{"xmodule-type": "Video"}
</script>
<h3 class="hd hd-2">Video</h3>
<div
id="video_video_c05f1e35755e"
class="video closed"
data-metadata='{"publishCompletionUrl": "/courses/course-v1:MITx+6.005.1x+3T2016/xblock/block-v1:MITx+6.005.1x+3T2016+type@video+block@video_c05f1e35755e/handler/publish_completion", "duration": 35.37, "transcriptLanguage": "en", "ytTestTimeout": 1500, "prioritizeHls": false, "generalSpeed": 1.0, "sources": ["https://d2f1egay8yehza.cloudfront.net/MIT600512016-V002200_DTH.mp4", "https://d2f1egay8yehza.cloudfront.net/MIT600512016-V002200/MIT600512016-V002200.m3u8"], "captionDataDir": null, "autoAdvance": false, "poster": null, "autohideHtml5": false, "speed": null, "transcriptTranslationUrl": "/courses/course-v1:MITx+6.005.1x+3T2016/xblock/block-v1:MITx+6.005.1x+3T2016+type@video+block@video_c05f1e35755e/handler/transcript/translation/__lang__", "recordedYoutubeIsAvailable": true, "completionEnabled": false, "end": 0.0, "ytMetadataEndpoint": "", "completionPercentage": 0.95, "savedVideoPosition": 0.0, "lmsRootURL": "https://openlearninglibrary.mit.edu", "saveStateEnabled": false, "start": 0.0, "streams": "1.00:vQfG5zOlQfU", "transcriptAvailableTranslationsUrl": "/courses/course-v1:MITx+6.005.1x+3T2016/xblock/block-v1:MITx+6.005.1x+3T2016+type@video+block@video_c05f1e35755e/handler/transcript/available_translations", "autoplay": false, "showCaptions": "true", "transcriptLanguages": {"en": "English"}, "saveStateUrl": "/courses/course-v1:MITx+6.005.1x+3T2016/xblock/block-v1:MITx+6.005.1x+3T2016+type@video+block@video_c05f1e35755e/handler/xmodule_handler/save_user_state", "ytApiUrl": "https://www.youtube.com/iframe_api"}'
data-bumper-metadata='null'
data-autoadvance-enabled="False"
data-poster='null'
tabindex="-1"
>
<div class="focus_grabber first"></div>
<div class="tc-wrapper">
<div class="video-wrapper">
<span tabindex="0" class="spinner" aria-hidden="false" aria-label="Loading video player"></span>
<span tabindex="-1" class="btn-play fa fa-youtube-play fa-2x is-hidden" aria-hidden="true" aria-label="Play video"></span>
<div class="video-player-pre"></div>
<div class="video-player">
<div id="video_c05f1e35755e"></div>
<h4 class="hd hd-4 video-error is-hidden">No playable video sources found.</h4>
<h4 class="hd hd-4 video-hls-error is-hidden">
Your browser does not support this video format. Try using a different browser.
</h4>
</div>
<div class="video-player-post"></div>
<div class="closed-captions"></div>
<div class="video-controls is-hidden">
<div>
<div class="vcr"><div class="vidtime">0:00 / 0:00</div></div>
<div class="secondary-controls"></div>
</div>
</div>
</div>
</div>
<div class="focus_grabber last"></div>
<h3 class="hd hd-4 downloads-heading sr" id="video-download-transcripts_video_c05f1e35755e">Downloads and transcripts</h3>
<div class="wrapper-downloads" role="region" aria-labelledby="video-download-transcripts_video_c05f1e35755e">
<div class="wrapper-download-transcripts">
<h4 class="hd hd-5">Transcripts</h4>
<ul class="list-download-transcripts">
<li class="transcript-option">
<a class="btn btn-link" href="/courses/course-v1:MITx+6.005.1x+3T2016/xblock/block-v1:MITx+6.005.1x+3T2016+type@video+block@video_c05f1e35755e/handler/transcript/download" data-value="srt">Download SubRip (.srt) file</a>
</li>
<li class="transcript-option">
<a class="btn btn-link" href="/courses/course-v1:MITx+6.005.1x+3T2016/xblock/block-v1:MITx+6.005.1x+3T2016+type@video+block@video_c05f1e35755e/handler/transcript/download" data-value="txt">Download Text (.txt) file</a>
</li>
</ul>
</div>
</div>
</div>
</div>
</div>
<div class="vert vert-1" data-id="block-v1:MITx+6.005.1x+3T2016+type@html+block@html_7394516ed26b">
<div class="xblock xblock-public_view xblock-public_view-html xmodule_display xmodule_HtmlBlock" data-course-id="course-v1:MITx+6.005.1x+3T2016" data-graded="True" data-init="XBlockToXModuleShim" data-request-token="9dc66f4a223711f0978c16ffcd2b1d4d" data-runtime-version="1" data-block-type="html" data-usage-id="block-v1:MITx+6.005.1x+3T2016+type@html+block@html_7394516ed26b" data-runtime-class="LmsRuntime" data-has-score="False">
<script type="json/xblock-args" class="xblock-json-init-args">
{"xmodule-type": "HTMLModule"}
</script>
<link href="/assets/courseware/v1/9fab367942e94f98d32835b3ef4df11d/asset-v1:MITx+6.005.1x+3T2016+type@asset+block/prism-edx-v1.css" rel="stylesheet" type="text/css" />
<h4>Software in 6.005</h4>
<table class="table table-striped no-markdown">
<tbody>
<tr>
<th width="33%">Safe from bugs</th>
<th>Easy to understand</th>
<th>Ready for change</th>
</tr>
<tr>
<td>
Correct today and correct in the unknown future
</td>
<td>
Communicates clearly with future programmers, including future you
</td>
<td>
Designed to accommodate change without rewriting
</td>
</tr>
</tbody>
</table>
<h4>Objectives for Today</h4>
<p>In today’s reading, we’ll talk about testing, which is the most widely-used practical technique for making code safe from bugs.</p>
<p>After today's reading, you should:</p>
<ul>
<li>understand the value of testing, and know the process of test-first programming;</li>
<li>be able to design a test suite for a method by partitioning its input and output space and choosing good test cases;</li>
<li>be able to judge a test suite by measuring its code coverage; and</li>
<li>understand and know when to use blackbox vs. whitebox testing, unit tests vs. integration tests, and automated regression testing. </li>
</ul>
</div>
</div>
</div>
</div>
<div class="xblock xblock-public_view xblock-public_view-vertical" data-course-id="course-v1:MITx+6.005.1x+3T2016" data-graded="True" data-init="VerticalStudentView" data-request-token="9dc66f4a223711f0978c16ffcd2b1d4d" data-runtime-version="1" data-block-type="vertical" data-usage-id="block-v1:MITx+6.005.1x+3T2016+type@vertical+block@Why_Software_Testing_is_Hard" data-runtime-class="LmsRuntime" data-has-score="False">
<h2 class="hd hd-2 unit-title">Why Software Testing is Hard</h2>
<div class="vert-mod">
<div class="vert vert-0" data-id="block-v1:MITx+6.005.1x+3T2016+type@video+block@video_892aa6d3fcd7">
<div class="xblock xblock-public_view xblock-public_view-video xmodule_display xmodule_VideoBlock" data-course-id="course-v1:MITx+6.005.1x+3T2016" data-graded="True" data-init="XBlockToXModuleShim" data-request-token="9dc66f4a223711f0978c16ffcd2b1d4d" data-runtime-version="1" data-block-type="video" data-usage-id="block-v1:MITx+6.005.1x+3T2016+type@video+block@video_892aa6d3fcd7" data-runtime-class="LmsRuntime" data-has-score="False">
<script type="json/xblock-args" class="xblock-json-init-args">
{"xmodule-type": "Video"}
</script>
<h3 class="hd hd-2">Video</h3>
<div
id="video_video_892aa6d3fcd7"
class="video closed"
data-metadata='{"publishCompletionUrl": "/courses/course-v1:MITx+6.005.1x+3T2016/xblock/block-v1:MITx+6.005.1x+3T2016+type@video+block@video_892aa6d3fcd7/handler/publish_completion", "duration": 346.26, "transcriptLanguage": "en", "ytTestTimeout": 1500, "prioritizeHls": false, "generalSpeed": 1.0, "sources": ["https://d2f1egay8yehza.cloudfront.net/MIT600512016-V002000_DTH.mp4", "https://d2f1egay8yehza.cloudfront.net/MIT600512016-V002000/MIT600512016-V002000.m3u8"], "captionDataDir": null, "autoAdvance": false, "poster": null, "autohideHtml5": false, "speed": null, "transcriptTranslationUrl": "/courses/course-v1:MITx+6.005.1x+3T2016/xblock/block-v1:MITx+6.005.1x+3T2016+type@video+block@video_892aa6d3fcd7/handler/transcript/translation/__lang__", "recordedYoutubeIsAvailable": true, "completionEnabled": false, "end": 0.0, "ytMetadataEndpoint": "", "completionPercentage": 0.95, "savedVideoPosition": 0.0, "lmsRootURL": "https://openlearninglibrary.mit.edu", "saveStateEnabled": false, "start": 0.0, "streams": "1.00:auFnlZzx3MY", "transcriptAvailableTranslationsUrl": "/courses/course-v1:MITx+6.005.1x+3T2016/xblock/block-v1:MITx+6.005.1x+3T2016+type@video+block@video_892aa6d3fcd7/handler/transcript/available_translations", "autoplay": false, "showCaptions": "true", "transcriptLanguages": {"en": "English"}, "saveStateUrl": "/courses/course-v1:MITx+6.005.1x+3T2016/xblock/block-v1:MITx+6.005.1x+3T2016+type@video+block@video_892aa6d3fcd7/handler/xmodule_handler/save_user_state", "ytApiUrl": "https://www.youtube.com/iframe_api"}'
data-bumper-metadata='null'
data-autoadvance-enabled="False"
data-poster='null'
tabindex="-1"
>
<div class="focus_grabber first"></div>
<div class="tc-wrapper">
<div class="video-wrapper">
<span tabindex="0" class="spinner" aria-hidden="false" aria-label="Loading video player"></span>
<span tabindex="-1" class="btn-play fa fa-youtube-play fa-2x is-hidden" aria-hidden="true" aria-label="Play video"></span>
<div class="video-player-pre"></div>
<div class="video-player">
<div id="video_892aa6d3fcd7"></div>
<h4 class="hd hd-4 video-error is-hidden">No playable video sources found.</h4>
<h4 class="hd hd-4 video-hls-error is-hidden">
Your browser does not support this video format. Try using a different browser.
</h4>
</div>
<div class="video-player-post"></div>
<div class="closed-captions"></div>
<div class="video-controls is-hidden">
<div>
<div class="vcr"><div class="vidtime">0:00 / 0:00</div></div>
<div class="secondary-controls"></div>
</div>
</div>
</div>
</div>
<div class="focus_grabber last"></div>
<h3 class="hd hd-4 downloads-heading sr" id="video-download-transcripts_video_892aa6d3fcd7">Downloads and transcripts</h3>
<div class="wrapper-downloads" role="region" aria-labelledby="video-download-transcripts_video_892aa6d3fcd7">
<div class="wrapper-download-transcripts">
<h4 class="hd hd-5">Transcripts</h4>
<ul class="list-download-transcripts">
<li class="transcript-option">
<a class="btn btn-link" href="/courses/course-v1:MITx+6.005.1x+3T2016/xblock/block-v1:MITx+6.005.1x+3T2016+type@video+block@video_892aa6d3fcd7/handler/transcript/download" data-value="srt">Download SubRip (.srt) file</a>
</li>
<li class="transcript-option">
<a class="btn btn-link" href="/courses/course-v1:MITx+6.005.1x+3T2016/xblock/block-v1:MITx+6.005.1x+3T2016+type@video+block@video_892aa6d3fcd7/handler/transcript/download" data-value="txt">Download Text (.txt) file</a>
</li>
</ul>
</div>
</div>
</div>
</div>
</div>
<div class="vert vert-1" data-id="block-v1:MITx+6.005.1x+3T2016+type@html+block@html_58f13bd7c9ff">
<div class="xblock xblock-public_view xblock-public_view-html xmodule_display xmodule_HtmlBlock" data-course-id="course-v1:MITx+6.005.1x+3T2016" data-graded="True" data-init="XBlockToXModuleShim" data-request-token="9dc66f4a223711f0978c16ffcd2b1d4d" data-runtime-version="1" data-block-type="html" data-usage-id="block-v1:MITx+6.005.1x+3T2016+type@html+block@html_58f13bd7c9ff" data-runtime-class="LmsRuntime" data-has-score="False">
<script type="json/xblock-args" class="xblock-json-init-args">
{"xmodule-type": "HTMLModule"}
</script>
<link href="/assets/courseware/v1/9fab367942e94f98d32835b3ef4df11d/asset-v1:MITx+6.005.1x+3T2016+type@asset+block/prism-edx-v1.css" rel="stylesheet" type="text/css" />
<h2 id="validation">Validation</h2>
<div data-outline="validation">
<p>Testing is an example of a more general process called <em>validation</em>. The purpose of validation is to uncover problems in a program and thereby increase your confidence in the program's correctness. Validation includes:</p>
<ul>
<li><strong>Formal reasoning</strong> about a program, usually called <em>verification</em>. Verification constructs a formal proof that a program is correct. Verification is tedious to do by hand, and automated tool support for verification is still an active area of research. Nevertheless, small, crucial pieces of a program may be formally verified, such as the scheduler in an operating system, or the bytecode interpreter in a virtual machine, or <a href="http://www.csail.mit.edu/crash_tolerant_data_storage">the filesystem in an operating system</a>.</li>
<li><strong>Code review.</strong> Having somebody else carefully read your code, and reason informally about it, can be a good way to uncover bugs. It's much like having somebody else proofread an essay you have written. We talked about code review in <a href="/courses/course-v1:MITx+6.005.1x+3T2016/jump_to_id/vertical-reading-2-objectives">another reading</a>. </li>
<li><strong>Testing</strong>. Running the program on carefully selected inputs and checking the results.</li>
</ul>
<p>Even with the best validation, it's very hard to achieve perfect quality in software. Here are some typical <em>residual defect rates</em> (bugs left over after the software has shipped) per kloc (one thousand lines of source code):</p>
<ul>
<li>1 - 10 defects/kloc: Typical industry software.</li>
<li>0.1 - 1 defects/kloc: High-quality validation. The Java libraries might achieve this level of correctness.</li>
<li>0.01 - 0.1 defects/kloc: The very best, safety-critical validation. NASA and aerospace companies can achieve this level.</li>
</ul>
<p>This can be discouraging for large systems. For example, if you have shipped a million lines of typical industry source code (1 defect/kloc), it means you missed 1000 bugs!</p>
</div>
<h2 id="why_software_testing_is_hard">Why Software Testing is Hard</h2>
<div data-outline="why_software_testing_is_hard">
<p>Here are some approaches that unfortunately don't work well in the world of software.</p>
<p><strong>Exhaustive testing</strong> is infeasible. The space of possible test cases is generally too big to cover exhaustively. Imagine exhaustively testing a 32-bit floating-point multiply operation, <code>a*b</code>. There are 2^64 test cases!</p>
<p><strong>Haphazard testing</strong> (“just try it and see if it works”) is less likely to find bugs, unless the program is so buggy that an arbitrarily-chosen input is more likely to fail than to succeed. It also doesn't increase our confidence in program correctness.</p>
<p><strong>Random or statistical testing</strong> doesn't work well for software. Other engineering disciplines can test small random samples (e.g. 1% of hard drives manufactured) and infer the defect rate for the whole production lot. Physical systems can use many tricks to speed up time, like opening a refrigerator 1000 times in 24 hours instead of 10 years. These tricks give known failure rates (e.g. mean lifetime of a hard drive), but they assume continuity or uniformity across the space of defects. This is true for physical artifacts.</p>
<p>But it's not true for software. Software behavior varies discontinuously and discretely across the space of possible inputs. Although the system may seem to work fine across a broad range of inputs, it could still abruptly fail at a single boundary point. The <a href="http://www.willamette.edu/~mjaneba/pentprob.html">famous Pentium division bug</a> affected approximately 1 in 9 billion divisions. Stack overflows, out of memory errors, and numeric overflow bugs tend to happen abruptly, and always in the same way, not with probabilistic variation. That's different from physical systems, where there is often visible evidence that the system is approaching a failure point (cracks in a bridge) or failures are distributed probabilistically near the failure point (so that statistical testing will observe some failures even before the point is reached). </p>
<p>Instead, test cases must be chosen carefully and systematically, and that's what we'll look at next.</p>
</div>
</div>
</div>
</div>
</div>
<div class="xblock xblock-public_view xblock-public_view-vertical" data-course-id="course-v1:MITx+6.005.1x+3T2016" data-graded="True" data-init="VerticalStudentView" data-request-token="9dc66f4a223711f0978c16ffcd2b1d4d" data-runtime-version="1" data-block-type="vertical" data-usage-id="block-v1:MITx+6.005.1x+3T2016+type@vertical+block@vertical_Questions_d90373e278d1" data-runtime-class="LmsRuntime" data-has-score="False">
<h2 class="hd hd-2 unit-title">Questions</h2>
<div class="vert-mod">
<div class="vert vert-0" data-id="block-v1:MITx+6.005.1x+3T2016+type@html+block@html_fff67ba8819a">
<div class="xblock xblock-public_view xblock-public_view-html xmodule_display xmodule_HtmlBlock" data-course-id="course-v1:MITx+6.005.1x+3T2016" data-graded="True" data-init="XBlockToXModuleShim" data-request-token="9dc66f4a223711f0978c16ffcd2b1d4d" data-runtime-version="1" data-block-type="html" data-usage-id="block-v1:MITx+6.005.1x+3T2016+type@html+block@html_fff67ba8819a" data-runtime-class="LmsRuntime" data-has-score="False">
<script type="json/xblock-args" class="xblock-json-init-args">
{"xmodule-type": "HTMLModule"}
</script>
<link href="/assets/courseware/v1/9fab367942e94f98d32835b3ef4df11d/asset-v1:MITx+6.005.1x+3T2016+type@asset+block/prism-edx-v1.css" rel="stylesheet" type="text/css" />
<link href="/assets/courseware/v1/9fab367942e94f98d32835b3ef4df11d/asset-v1:MITx+6.005.1x+3T2016+type@asset+block/prism-edx-v1.css" rel="stylesheet" type="text/css" />
<script src="/assets/courseware/v1/3e6443fb95285d2dc06e8ffc448b9bdf/asset-v1:MITx+6.005.1x+3T2016+type@asset+block/prism.js"></script>
<script src="/assets/courseware/v1/2ba76f8bdfef4e2d45e31a3dc5208470/asset-v1:MITx+6.005.1x+3T2016+type@asset+block/edx-script-v1.js"></script>
</div>
</div>
<div class="vert vert-1" data-id="block-v1:MITx+6.005.1x+3T2016+type@problem+block@03-testing-basics">
<div class="xblock xblock-public_view xblock-public_view-problem xmodule_display xmodule_ProblemBlock" data-course-id="course-v1:MITx+6.005.1x+3T2016" data-graded="True" data-init="XBlockToXModuleShim" data-request-token="9dc66f4a223711f0978c16ffcd2b1d4d" data-runtime-version="1" data-block-type="problem" data-usage-id="block-v1:MITx+6.005.1x+3T2016+type@problem+block@03-testing-basics" data-runtime-class="LmsRuntime" data-has-score="True">
<script type="json/xblock-args" class="xblock-json-init-args">
{"xmodule-type": "Problem"}
</script>
<div id="problem_03-testing-basics" class="problems-wrapper" role="group"
aria-labelledby="03-testing-basics-problem-title"
data-problem-id="block-v1:MITx+6.005.1x+3T2016+type@problem+block@03-testing-basics" data-url="/courses/course-v1:MITx+6.005.1x+3T2016/xblock/block-v1:MITx+6.005.1x+3T2016+type@problem+block@03-testing-basics/handler/xmodule_handler"
data-problem-score="0"
data-problem-total-possible="1"
data-attempts-used="0"
data-content="
<h3 class="hd hd-3 problem-header" id="03-testing-basics-problem-title" aria-describedby="block-v1:MITx+6.005.1x+3T2016+type@problem+block@03-testing-basics-problem-progress" tabindex="-1">
testing basics
</h3>
<div class="problem-progress" id="block-v1:MITx+6.005.1x+3T2016+type@problem+block@03-testing-basics-problem-progress"></div>
<div class="problem">
<div>
<p>In the 1990s, the Ariane 5 launch vehicle, designed and built for the European Space Agency, self-destructed 37 seconds after its first launch. </p>
<p>The reason was a control software bug that went undetected. The Ariane 5&#8217;s guidance software was reused from the Ariane 4, which was a slower rocket. When the velocity calculation converted from a 64-bit floating point number (a <code>double</code> in Java terminology, though this software wasn&#8217;t written in Java) to a 16-bit signed integer (a <code>short</code>), it overflowed the small integer and caused an exception to be thrown. The exception handler had been disabled for efficiency reasons, so the guidance software crashed. Without guidance, the rocket crashed too. The cost of the failure was $1 billion.</p>
<p>What ideas does this story demonstrate? Check all that apply.</p>
<div class="wrapper-problem-response" tabindex="-1" aria-label="Question 1" role="group"><div class="choicegroup capa_inputtype" id="inputtype_03-testing-basics_2_1">
<fieldset aria-describedby="status_03-testing-basics_2_1">
<div class="field">
<input type="checkbox" name="input_03-testing-basics_2_1[]" id="input_03-testing-basics_2_1_choice_0" class="field-input input-checkbox" value="choice_0"/><label id="03-testing-basics_2_1-choice_0-label" for="input_03-testing-basics_2_1_choice_0" class="response-label field-label label-inline" aria-describedby="status_03-testing-basics_2_1"> Even high-quality safety-critical software may still have residual bugs.
</label>
</div>
<div class="field">
<input type="checkbox" name="input_03-testing-basics_2_1[]" id="input_03-testing-basics_2_1_choice_1" class="field-input input-checkbox" value="choice_1"/><label id="03-testing-basics_2_1-choice_1-label" for="input_03-testing-basics_2_1_choice_1" class="response-label field-label label-inline" aria-describedby="status_03-testing-basics_2_1"> Testing all possible inputs is the best solution to this problem.
</label>
</div>
<div class="field">
<input type="checkbox" name="input_03-testing-basics_2_1[]" id="input_03-testing-basics_2_1_choice_2" class="field-input input-checkbox" value="choice_2"/><label id="03-testing-basics_2_1-choice_2-label" for="input_03-testing-basics_2_1_choice_2" class="response-label field-label label-inline" aria-describedby="status_03-testing-basics_2_1"> Software exhibits discontinuous behavior, unlike many physically-engineered systems.
</label>
</div>
<div class="field">
<input type="checkbox" name="input_03-testing-basics_2_1[]" id="input_03-testing-basics_2_1_choice_3" class="field-input input-checkbox" value="choice_3"/><label id="03-testing-basics_2_1-choice_3-label" for="input_03-testing-basics_2_1_choice_3" class="response-label field-label label-inline" aria-describedby="status_03-testing-basics_2_1"> Static type checking could have detected this bug.
</label>
</div>
<span id="answer_03-testing-basics_2_1"/>
</fieldset>
<div class="indicator-container">
<span class="status unanswered" id="status_03-testing-basics_2_1" data-tooltip="Not yet answered.">
<span class="sr">unanswered</span><span class="status-icon" aria-hidden="true"/>
</span>
</div>
</div></div>
<div class="solution-span">
<span id="solution_03-testing-basics_solution_1"/>
</div></div>
<div class="action">
<input type="hidden" name="problem_id" value="testing basics" />
<div class="submit-attempt-container">
<button type="button" class="submit btn-brand" data-submitting="Submitting" data-value="Submit" data-should-enable-submit-button="True" aria-describedby="submission_feedback_03-testing-basics" >
<span class="submit-label">Submit</span>
</button>
<div class="submission-feedback" id="submission_feedback_03-testing-basics">
<span class="sr">Some problems have options such as save, reset, hints, or show answer. These options follow the Submit button.</span>
</div>
</div>
<div class="problem-action-buttons-wrapper">
</div>
</div>
<div class="notification warning notification-gentle-alert
is-hidden"
tabindex="-1">
<span class="icon fa fa-exclamation-circle" aria-hidden="true"></span>
<span class="notification-message" aria-describedby="03-testing-basics-problem-title">
</span>
<div class="notification-btn-wrapper">
<button type="button" class="btn btn-default btn-small notification-btn review-btn sr">Review</button>
</div>
</div>
<div class="notification warning notification-save
is-hidden"
tabindex="-1">
<span class="icon fa fa-save" aria-hidden="true"></span>
<span class="notification-message" aria-describedby="03-testing-basics-problem-title">None
</span>
<div class="notification-btn-wrapper">
<button type="button" class="btn btn-default btn-small notification-btn review-btn sr">Review</button>
</div>
</div>
<div class="notification general notification-show-answer
is-hidden"
tabindex="-1">
<span class="icon fa fa-info-circle" aria-hidden="true"></span>
<span class="notification-message" aria-describedby="03-testing-basics-problem-title">Answers are displayed within the problem
</span>
<div class="notification-btn-wrapper">
<button type="button" class="btn btn-default btn-small notification-btn review-btn sr">Review</button>
</div>
</div>
</div>
"
data-graded="True">
<p class="loading-spinner">
<i class="fa fa-spinner fa-pulse fa-2x fa-fw"></i>
<span class="sr">Loading…</span>
</p>
</div>
</div>
</div>
</div>
</div>
<div class="xblock xblock-public_view xblock-public_view-vertical" data-course-id="course-v1:MITx+6.005.1x+3T2016" data-graded="True" data-init="VerticalStudentView" data-request-token="9dc66f4a223711f0978c16ffcd2b1d4d" data-runtime-version="1" data-block-type="vertical" data-usage-id="block-v1:MITx+6.005.1x+3T2016+type@vertical+block@vertical-test-first-programming-partitioning" data-runtime-class="LmsRuntime" data-has-score="False">
<h2 class="hd hd-2 unit-title">Test-First Programming; Partitioning</h2>
<div class="vert-mod">
<div class="vert vert-0" data-id="block-v1:MITx+6.005.1x+3T2016+type@video+block@video_d779793cb072">
<div class="xblock xblock-public_view xblock-public_view-video xmodule_display xmodule_VideoBlock" data-course-id="course-v1:MITx+6.005.1x+3T2016" data-graded="True" data-init="XBlockToXModuleShim" data-request-token="9dc66f4a223711f0978c16ffcd2b1d4d" data-runtime-version="1" data-block-type="video" data-usage-id="block-v1:MITx+6.005.1x+3T2016+type@video+block@video_d779793cb072" data-runtime-class="LmsRuntime" data-has-score="False">
<script type="json/xblock-args" class="xblock-json-init-args">
{"xmodule-type": "Video"}
</script>
<h3 class="hd hd-2">Video</h3>
<div
id="video_video_d779793cb072"
class="video closed"
data-metadata='{"publishCompletionUrl": "/courses/course-v1:MITx+6.005.1x+3T2016/xblock/block-v1:MITx+6.005.1x+3T2016+type@video+block@video_d779793cb072/handler/publish_completion", "duration": 898.01, "transcriptLanguage": "en", "ytTestTimeout": 1500, "prioritizeHls": false, "generalSpeed": 1.0, "sources": ["https://d2f1egay8yehza.cloudfront.net/MIT600512016-V002100_DTH.mp4", "https://d2f1egay8yehza.cloudfront.net/MIT600512016-V002100/MIT600512016-V002100.m3u8"], "captionDataDir": null, "autoAdvance": false, "poster": null, "autohideHtml5": false, "speed": null, "transcriptTranslationUrl": "/courses/course-v1:MITx+6.005.1x+3T2016/xblock/block-v1:MITx+6.005.1x+3T2016+type@video+block@video_d779793cb072/handler/transcript/translation/__lang__", "recordedYoutubeIsAvailable": true, "completionEnabled": false, "end": 0.0, "ytMetadataEndpoint": "", "completionPercentage": 0.95, "savedVideoPosition": 0.0, "lmsRootURL": "https://openlearninglibrary.mit.edu", "saveStateEnabled": false, "start": 0.0, "streams": "1.00:7pxMDB1C3-4", "transcriptAvailableTranslationsUrl": "/courses/course-v1:MITx+6.005.1x+3T2016/xblock/block-v1:MITx+6.005.1x+3T2016+type@video+block@video_d779793cb072/handler/transcript/available_translations", "autoplay": false, "showCaptions": "true", "transcriptLanguages": {"en": "English"}, "saveStateUrl": "/courses/course-v1:MITx+6.005.1x+3T2016/xblock/block-v1:MITx+6.005.1x+3T2016+type@video+block@video_d779793cb072/handler/xmodule_handler/save_user_state", "ytApiUrl": "https://www.youtube.com/iframe_api"}'
data-bumper-metadata='null'
data-autoadvance-enabled="False"
data-poster='null'
tabindex="-1"
>
<div class="focus_grabber first"></div>
<div class="tc-wrapper">
<div class="video-wrapper">
<span tabindex="0" class="spinner" aria-hidden="false" aria-label="Loading video player"></span>
<span tabindex="-1" class="btn-play fa fa-youtube-play fa-2x is-hidden" aria-hidden="true" aria-label="Play video"></span>
<div class="video-player-pre"></div>
<div class="video-player">
<div id="video_d779793cb072"></div>
<h4 class="hd hd-4 video-error is-hidden">No playable video sources found.</h4>
<h4 class="hd hd-4 video-hls-error is-hidden">
Your browser does not support this video format. Try using a different browser.
</h4>
</div>
<div class="video-player-post"></div>
<div class="closed-captions"></div>
<div class="video-controls is-hidden">
<div>
<div class="vcr"><div class="vidtime">0:00 / 0:00</div></div>
<div class="secondary-controls"></div>
</div>
</div>
</div>
</div>
<div class="focus_grabber last"></div>
<h3 class="hd hd-4 downloads-heading sr" id="video-download-transcripts_video_d779793cb072">Downloads and transcripts</h3>
<div class="wrapper-downloads" role="region" aria-labelledby="video-download-transcripts_video_d779793cb072">
<div class="wrapper-download-transcripts">
<h4 class="hd hd-5">Transcripts</h4>
<ul class="list-download-transcripts">
<li class="transcript-option">
<a class="btn btn-link" href="/courses/course-v1:MITx+6.005.1x+3T2016/xblock/block-v1:MITx+6.005.1x+3T2016+type@video+block@video_d779793cb072/handler/transcript/download" data-value="srt">Download SubRip (.srt) file</a>
</li>
<li class="transcript-option">
<a class="btn btn-link" href="/courses/course-v1:MITx+6.005.1x+3T2016/xblock/block-v1:MITx+6.005.1x+3T2016+type@video+block@video_d779793cb072/handler/transcript/download" data-value="txt">Download Text (.txt) file</a>
</li>
</ul>
</div>
</div>
</div>
</div>
</div>
<div class="vert vert-1" data-id="block-v1:MITx+6.005.1x+3T2016+type@html+block@html_e8e0d496467c">
<div class="xblock xblock-public_view xblock-public_view-html xmodule_display xmodule_HtmlBlock" data-course-id="course-v1:MITx+6.005.1x+3T2016" data-graded="True" data-init="XBlockToXModuleShim" data-request-token="9dc66f4a223711f0978c16ffcd2b1d4d" data-runtime-version="1" data-block-type="html" data-usage-id="block-v1:MITx+6.005.1x+3T2016+type@html+block@html_e8e0d496467c" data-runtime-class="LmsRuntime" data-has-score="False">
<script type="json/xblock-args" class="xblock-json-init-args">
{"xmodule-type": "HTMLModule"}
</script>
<link href="/assets/courseware/v1/9fab367942e94f98d32835b3ef4df11d/asset-v1:MITx+6.005.1x+3T2016+type@asset+block/prism-edx-v1.css" rel="stylesheet" type="text/css" />
<h2 id="putting_on_your_testing_hat">Putting on Your Testing Hat</h2>
<div data-outline="putting_on_your_testing_hat">
<p>Testing requires having the right attitude. When you're coding, your goal is to make the program work, but as a tester, you want to <strong>make it fail</strong>. </p>
<p>That's a subtle but important difference. It is all too tempting to treat code you've just written as a precious thing, a fragile eggshell, and test it very lightly just to see it work.</p>
<p>Instead, you have to be brutal. A good tester wields a sledgehammer and beats the program everywhere it might be vulnerable, so that those vulnerabilities can be eliminated.</p>
</div>
<h2 id="test-first_programming">Test-first Programming</h2>
<div data-outline="test-first_programming">
<p>Test early and often. Don't leave testing until the end, when you have a big pile of unvalidated code. Leaving testing until the end only makes debugging longer and more painful, because bugs may be anywhere in your code. It's far more pleasant to test your code as you develop it.</p>
<p>In test-first-programming, you write tests before you even write any code. The development of a single function proceeds in this order:</p>
<ol>
<li>Write a specification for the function.</li>
<li>Write tests that exercise the specification. </li>
<li>Write the actual code. Once your code passes the tests you wrote, you're done.</li>
</ol>
<p>The <strong>specification</strong> describes the input and output behavior of the function. It gives the types of the parameters and any additional constraints on them (e.g. <code>sqrt</code>'s parameter must be nonnegative). It also gives the type of the return value and describes how the return value relates to the inputs. You've already seen and used specifications on your problem sets in this class. In code, the specification consists of the method signature and the comment above it that describes what it does. We'll have much more to say about specifications a few classes from now.</p>
<p>Writing tests first is a good way to understand the specification. The specification can be buggy, too — incorrect, incomplete, ambiguous, missing corner cases. Trying to write tests can uncover these problems early, before you've wasted time writing an implementation of a buggy spec.</p>
</div>
<h2 id="choosing_test_cases_by_partitioning">Choosing Test Cases by Partitioning</h2>
<div data-outline="choosing_test_cases_by_partitioning">
<p>Creating a good test suite is a challenging and interesting design problem. We want to pick a set of test cases that is small enough to run quickly, yet large enough to validate the program. </p>
<div class="panel panel-figure pull-right pull-margin"><img src="/assets/courseware/v1/bebd95c507e983c4947658c2ee949994/asset-v1:MITx+6.005.1x+3T2016+type@asset+block/03-partition.png" alt="partitioning a function's input space" width="200"></div>
<p>To do this, we divide the input space into <strong>subdomains</strong>, each consisting of a set of inputs. Taken together the subdomains completely cover the input space, so that every input lies in at least one subdomain. Then we choose one test case from each subdomain, and that's our test suite.</p>
<p>The idea behind subdomains is to partition the input space into sets of similar inputs on which the program has similar behavior. Then we use one representative of each set. This approach makes the best use of limited testing resources by choosing dissimilar test cases, and forcing the testing to explore parts of the input space that random testing might not reach.</p>
<p>We can also partition the output space into subdomains (similar outputs on which the program has similar behavior) if we need to ensure our tests will explore different parts of the output space. Most of the time, partitioning the input space is sufficient.</p>
<div class="clearfix"></div>
<h4>Example: <code>BigInteger.multiply()</code></h4>
<p>Let's look at an example. <a href="http://docs.oracle.com/javase/8/docs/api/?java/math/BigInteger.html"><code>BigInteger</code></a> is a class built into the Java library that can represent integers of any size, unlike the primitive types <code>int</code> and <code>long</code> that have only limited ranges. BigInteger has a method <code>multiply</code> that multiplies two BigInteger values together:</p><pre><code class="hljs php"><span class="hljs-comment">/**
* <span class="hljs-doctag">@param</span> val another BigIntger
* <span class="hljs-doctag">@return</span> a BigInteger whose value is (this * val).
*/</span>
<span class="hljs-keyword">public</span> BigInteger multiply(BigInteger val)
</code></pre>
<p>For example, here's how it might be used:</p><pre><code class="hljs nginx"><span class="hljs-title">BigInteger</span> a = ...;
<span class="hljs-title">BigInteger</span> b = ...;
<span class="hljs-title">BigInteger</span> ab = a.multiply(b);
</code></pre>
<p>This example shows that even though only one parameter is explicitly shown in the method's declaration, <code>multiply</code> is actually a function of <em>two</em> arguments: the object you're calling the method on (<code>a</code> in the example above), and the parameter that you're passing in the parentheses (<code>b</code> in this example). In Python, the object receiving the method call would be explicitly named as a parameter called <code>self</code> in the method declaration. In Java, you don't mention the receiving object in the parameters, and it's called <code>this</code> instead of <code>self</code>.</p>
<p>So we should think of <code>multiply</code> as a function taking two inputs, each of type <code>BigInteger</code>, and producing one output of type <code>BigInteger</code>:</p>
<p><strong><code>multiply : BigInteger × BigInteger → BigInteger</code></strong></p>
<p>So we have a two-dimensional input space, consisting of all the pairs of integers (a,b). Now let's partition it. Thinking about how multiplication works, we might start with these partitions:</p>
<ul>
<li>a and b are both positive</li>
<li>a and b are both negative</li>
<li>a is positive, b is negative</li>
<li>a is negative, b is positive</li>
</ul>
<p>There are also some special cases for multiplication that we should check: 0, 1, and -1.</p>
<ul>
<li>a or b is 0, 1, or -1</li>
</ul>
<p>Finally, as a suspicious tester trying to find bugs, we might suspect that the implementor of BigInteger might try to make it faster by using <code>int</code> or <code>long</code> internally when possible and only fall back on an expensive general representation (like a list of digits) when the value is too big. So we should definitely also try integers that are very big, bigger than the biggest <code>long</code>.</p>
<ul>
<li>a or b is small</li>
<li>the absolute value of a or b is bigger than <code>Long.MAX_VALUE</code>, the biggest possible primitive integer in Java, which is roughly 2^63.</li>
</ul>
<p>Let's bring all these observations together into a straightforward partition of the whole <code>(a,b)</code> space. We'll choose <code>a</code> and <code>b</code> independently from:</p>
<div class="panel panel-figure pull-right pull-margin"><img src="/assets/courseware/v1/0f0e93375abe5ce19866369c593e7002/asset-v1:MITx+6.005.1x+3T2016+type@asset+block/03-multiply-partition.png" alt="partitioning multiply()" width="400"></div>
<ul>
<li>0</li>
<li>1</li>
<li>-1</li>
<li>small positive integer</li>
<li>small negative integer</li>
<li>huge positive integer</li>
<li>huge negative integer</li>
</ul>
<p>So this will produce 7 × 7 = 49 partitions that completely cover the space of pairs of integers.</p>
<p>To produce the test suite, we would pick an arbitrary pair (a,b) from each square of the grid, for example:</p>
<ul>
<li>(a,b) = (-3, 25) to cover (small negative, small positive)</li>
<li>(a,b) = (0, 30) to cover (0, small positive)</li>
<li>(a,b) = (2^100, 1) to cover (large positive, 1)</li>
<li>etc.</li>
</ul>
<p>The figure at the right shows how the two-dimensional (a,b) space is divided by this partition, and the points are test cases that we might choose to completely cover the partition.</p>
<div class="clearfix"></div>
<h4>Example: <code>max()</code></h4>
<p>Let's look at another example from the Java library: the integer <code>max()</code> function, found in the <a href="http://docs.oracle.com/javase/8/docs/api/java/lang/Math.html"><code>Math</code></a> class.</p><pre><code class="language-java hljs"><span class="hljs-comment">/**
* <span class="hljs-doctag">@param</span> a an argument
* <span class="hljs-doctag">@param</span> b another argument
* <span class="hljs-doctag">@return</span> the larger of a and b.
*/</span>
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">int</span> <span class="hljs-title">max</span><span class="hljs-params">(<span class="hljs-keyword">int</span> a, <span class="hljs-keyword">int</span> b)</span></span></code></pre>
<p>Mathematically, this method is a function of the following type:</p>
<p><strong><code>max : int × int → int</code></strong></p>
<div class="panel panel-figure pull-right pull-margin"><img src="/assets/courseware/v1/fec68cbee145c3fbbad96c5b1a3143d2/asset-v1:MITx+6.005.1x+3T2016+type@asset+block/03-max-partition.png" alt="partitioning-max" width="200"></div>
<p>From the specification, it makes sense to partition this function as:</p>
<ul>
<li>a < b</li>
<li>a = b</li>
<li>a > b</li>
</ul>
<p>Our test suite might then be:</p>
<ul>
<li>(a, b) = (1, 2) to cover a < b</li>
<li>(a, b) = (9, 9) to cover a = b</li>
<li>(a, b) = (-5, -6) to cover a > b</li>
</ul>
<div class="clearfix"></div>
<h3 id="include_boundaries_in_the_partition">Include Boundaries in the Partition</h3>
<div data-outline="include_boundaries_in_the_partition">
<p>Bugs often occur at <em>boundaries</em> between subdomains. Some examples:</p>
<ul>
<li>0 is a boundary between positive numbers and negative numbers</li>
<li>the maximum and minimum values of numeric types, like <code>int</code> and <code>double</code></li>
<li>emptiness (the empty string, empty list, empty array) for collection types</li>
<li>the first and last element of a collection</li>
</ul>
<p>Why do bugs often happen at boundaries? One reason is that programmers often make <strong>off-by-one mistakes</strong> (like writing <code><=</code> instead of <code><</code>, or initializing a counter to 0 instead of 1). Another is that some boundaries may need to be handled as special cases in the code. Another is that boundaries may be places of discontinuity in the code's behavior. When an <code>int</code> variable grows beyond its maximum positive value, for example, it abruptly becomes a negative number. </p>
<p>It's important to include boundaries as subdomains in your partition, so that you're choosing an input from the boundary. </p>
<p>Let's redo <strong><code>max : int × int → int</code></strong>.</p>
<p>Partition into:</p>
<ul>
<li><em>relationship between a and b</em>
<ul>
<li>a < b</li>
<li>a = b</li>
<li>a > b</li>
</ul>
</li>
<li><em>value of a</em>
<ul>
<li>a = 0</li>
<li>a < 0</li>
<li>a > 0</li>
<li>a = minimum integer</li>
<li>a = maximum integer</li>
</ul>
</li>
<li><em>value of b</em>
<ul>
<li>b = 0</li>
<li>b < 0</li>
<li>b > 0</li>
<li>b = minimum integer</li>
<li>b = maximum integer</li>
</ul>
</li>
</ul>
<p>Now let's pick test values that cover all these classes:</p>
<ul>
<li>(1, 2) covers a < b, a > 0, b > 0</li>
<li>(-1, -3) covers a > b, a < 0, b < 0</li>
<li>(0, 0) covers a = b, a = 0, b = 0</li>
<li>(Integer.MIN_VALUE, Integer.MAX_VALUE) covers a < b, a = minint, b = maxint</li>
<li>(Integer.MAX_VALUE, Integer.MIN_VALUE) covers a > b, a = maxint, b = minint</li>
</ul>
</div>
<h3 id="two_extremes_for_covering_the_partition">Two Extremes for Covering the Partition</h3>
<div data-outline="two_extremes_for_covering_the_partition">
<p>After partitioning the input space, we can choose how exhaustive we want the test suite to be:</p>
<ul>
<li>
<p><strong>Full Cartesian product</strong>.
<br> Every legal combination of the partition dimensions is covered by one test case. This is what we did for the <code>multiply</code> example, and it gave us 7 × 7 = 49 test cases. For the <code>max</code> example that included boundaries, which has three dimensions with 3 parts, 5 parts, and 5 parts respectively, it would mean up to 3 × 5 × 5 = 75 test cases. In practice not all of these combinations are possible, however. For example, there's no way to cover the combination a < b, a=0, b=0, because <code>a</code> can't be simultaneously less than zero and equal to zero.</p>
</li>
<li>
<p><strong>Cover each part.</strong>
<br> Every part of each dimension is covered by at least one test case, but not necessarily every combination. With this approach, the test suite for <code>max</code> might be as small as 5 test cases if carefully chosen. That's the approach we took above, which allowed us to choose 5 test cases.</p>
</li>
</ul>
<p>Often we strike some compromise between these two extremes, based on human judgement and caution, and influenced by whitebox testing and code coverage tools, which we look at next.</p>
</div>
</div>
</div>
</div>
</div>
<div class="xblock xblock-public_view xblock-public_view-vertical" data-course-id="course-v1:MITx+6.005.1x+3T2016" data-graded="True" data-init="VerticalStudentView" data-request-token="9dc66f4a223711f0978c16ffcd2b1d4d" data-runtime-version="1" data-block-type="vertical" data-usage-id="block-v1:MITx+6.005.1x+3T2016+type@vertical+block@vertical-partitioning-questions" data-runtime-class="LmsRuntime" data-has-score="False">
<h2 class="hd hd-2 unit-title">Questions</h2>
<div class="vert-mod">
<div class="vert vert-0" data-id="block-v1:MITx+6.005.1x+3T2016+type@html+block@html_fff67ba8819a">
<div class="xblock xblock-public_view xblock-public_view-html xmodule_display xmodule_HtmlBlock" data-course-id="course-v1:MITx+6.005.1x+3T2016" data-graded="True" data-init="XBlockToXModuleShim" data-request-token="9dc66f4a223711f0978c16ffcd2b1d4d" data-runtime-version="1" data-block-type="html" data-usage-id="block-v1:MITx+6.005.1x+3T2016+type@html+block@html_fff67ba8819a" data-runtime-class="LmsRuntime" data-has-score="False">
<script type="json/xblock-args" class="xblock-json-init-args">
{"xmodule-type": "HTMLModule"}
</script>
<link href="/assets/courseware/v1/9fab367942e94f98d32835b3ef4df11d/asset-v1:MITx+6.005.1x+3T2016+type@asset+block/prism-edx-v1.css" rel="stylesheet" type="text/css" />
<link href="/assets/courseware/v1/9fab367942e94f98d32835b3ef4df11d/asset-v1:MITx+6.005.1x+3T2016+type@asset+block/prism-edx-v1.css" rel="stylesheet" type="text/css" />
<script src="/assets/courseware/v1/3e6443fb95285d2dc06e8ffc448b9bdf/asset-v1:MITx+6.005.1x+3T2016+type@asset+block/prism.js"></script>
<script src="/assets/courseware/v1/2ba76f8bdfef4e2d45e31a3dc5208470/asset-v1:MITx+6.005.1x+3T2016+type@asset+block/edx-script-v1.js"></script>
</div>
</div>
<div class="vert vert-1" data-id="block-v1:MITx+6.005.1x+3T2016+type@problem+block@03-partitioning">
<div class="xblock xblock-public_view xblock-public_view-problem xmodule_display xmodule_ProblemBlock" data-course-id="course-v1:MITx+6.005.1x+3T2016" data-graded="True" data-init="XBlockToXModuleShim" data-request-token="9dc66f4a223711f0978c16ffcd2b1d4d" data-runtime-version="1" data-block-type="problem" data-usage-id="block-v1:MITx+6.005.1x+3T2016+type@problem+block@03-partitioning" data-runtime-class="LmsRuntime" data-has-score="True">
<script type="json/xblock-args" class="xblock-json-init-args">
{"xmodule-type": "Problem"}
</script>
<div id="problem_03-partitioning" class="problems-wrapper" role="group"
aria-labelledby="03-partitioning-problem-title"
data-problem-id="block-v1:MITx+6.005.1x+3T2016+type@problem+block@03-partitioning" data-url="/courses/course-v1:MITx+6.005.1x+3T2016/xblock/block-v1:MITx+6.005.1x+3T2016+type@problem+block@03-partitioning/handler/xmodule_handler"
data-problem-score="0"
data-problem-total-possible="1"
data-attempts-used="0"
data-content="
<h3 class="hd hd-3 problem-header" id="03-partitioning-problem-title" aria-describedby="block-v1:MITx+6.005.1x+3T2016+type@problem+block@03-partitioning-problem-progress" tabindex="-1">
partitioning
</h3>
<div class="problem-progress" id="block-v1:MITx+6.005.1x+3T2016+type@problem+block@03-partitioning-problem-progress"></div>
<div class="problem">
<div>
<p>Consider the following specification:</p>
<pre class="code">
/**
* Reverses the end of a string.
*
* 012345 012345
* For example: reverseEnd("Hello, world", 5) returns "Hellodlrow ,"
* &lt;-----&gt; &lt;-----&gt;
*
* With start == 0, reverses the entire text.
* With start == text.length(), reverses nothing.
*
* @param text non-null String that will have its end reversed
* @param start the index at which the remainder of the input is reversed,
* requires 0 &lt;= start &lt;= text.length()
* @return input text with the substring from start to the end of the string reversed
*/
public static String reverseEnd(String text, int start)
</pre>
<p>Which of the following are reasonable partitions for the start parameter? Check all that apply.</p>
<div class="wrapper-problem-response" tabindex="-1" aria-label="Question 1" role="group"><div id="inputtype_03-partitioning_2_1" class="choicegroup capa_inputtype">
<fieldset aria-describedby="status_03-partitioning_2_1">
<div class="field">
<input type="checkbox" id="input_03-partitioning_2_1_choice_0" name="input_03-partitioning_2_1[]" class="field-input input-checkbox" value="choice_0"/><label id="03-partitioning_2_1-choice_0-label" for="input_03-partitioning_2_1_choice_0" aria-describedby="status_03-partitioning_2_1" class="response-label field-label label-inline"> start = 0, start = 5, start = 100
</label>
</div>
<div class="field">
<input type="checkbox" id="input_03-partitioning_2_1_choice_1" name="input_03-partitioning_2_1[]" class="field-input input-checkbox" value="choice_1"/><label id="03-partitioning_2_1-choice_1-label" for="input_03-partitioning_2_1_choice_1" aria-describedby="status_03-partitioning_2_1" class="response-label field-label label-inline"> start &lt; 0, start = 0, start &gt; 0
</label>
</div>
<div class="field">
<input type="checkbox" id="input_03-partitioning_2_1_choice_2" name="input_03-partitioning_2_1[]" class="field-input input-checkbox" value="choice_2"/><label id="03-partitioning_2_1-choice_2-label" for="input_03-partitioning_2_1_choice_2" aria-describedby="status_03-partitioning_2_1" class="response-label field-label label-inline"> start = 0, 0 &lt; start &lt; text.length(), start = text.length()
</label>
</div>
<div class="field">
<input type="checkbox" id="input_03-partitioning_2_1_choice_3" name="input_03-partitioning_2_1[]" class="field-input input-checkbox" value="choice_3"/><label id="03-partitioning_2_1-choice_3-label" for="input_03-partitioning_2_1_choice_3" aria-describedby="status_03-partitioning_2_1" class="response-label field-label label-inline"> start &lt; text.length(), start = text.length(), start &gt; text.length()
</label>
</div>
<span id="answer_03-partitioning_2_1"/>
</fieldset>
<div class="indicator-container">
<span id="status_03-partitioning_2_1" data-tooltip="Not yet answered." class="status unanswered">
<span class="sr">unanswered</span><span class="status-icon" aria-hidden="true"/>
</span>
</div>
</div></div>
<div class="solution-span">
<span id="solution_03-partitioning_solution_1"/>
</div></div>
<div class="action">
<input type="hidden" name="problem_id" value="partitioning" />
<div class="submit-attempt-container">
<button type="button" class="submit btn-brand" data-submitting="Submitting" data-value="Submit" data-should-enable-submit-button="True" aria-describedby="submission_feedback_03-partitioning" >
<span class="submit-label">Submit</span>
</button>
<div class="submission-feedback" id="submission_feedback_03-partitioning">
<span class="sr">Some problems have options such as save, reset, hints, or show answer. These options follow the Submit button.</span>
</div>
</div>
<div class="problem-action-buttons-wrapper">
</div>
</div>
<div class="notification warning notification-gentle-alert
is-hidden"
tabindex="-1">
<span class="icon fa fa-exclamation-circle" aria-hidden="true"></span>
<span class="notification-message" aria-describedby="03-partitioning-problem-title">
</span>
<div class="notification-btn-wrapper">
<button type="button" class="btn btn-default btn-small notification-btn review-btn sr">Review</button>
</div>
</div>
<div class="notification warning notification-save
is-hidden"
tabindex="-1">
<span class="icon fa fa-save" aria-hidden="true"></span>
<span class="notification-message" aria-describedby="03-partitioning-problem-title">None
</span>
<div class="notification-btn-wrapper">
<button type="button" class="btn btn-default btn-small notification-btn review-btn sr">Review</button>
</div>
</div>
<div class="notification general notification-show-answer
is-hidden"
tabindex="-1">
<span class="icon fa fa-info-circle" aria-hidden="true"></span>
<span class="notification-message" aria-describedby="03-partitioning-problem-title">Answers are displayed within the problem
</span>
<div class="notification-btn-wrapper">
<button type="button" class="btn btn-default btn-small notification-btn review-btn sr">Review</button>
</div>
</div>
</div>
"
data-graded="True">
<p class="loading-spinner">
<i class="fa fa-spinner fa-pulse fa-2x fa-fw"></i>
<span class="sr">Loading…</span>
</p>
</div>
</div>
</div>
<div class="vert vert-2" data-id="block-v1:MITx+6.005.1x+3T2016+type@problem+block@03-partitioning-a-string">
<div class="xblock xblock-public_view xblock-public_view-problem xmodule_display xmodule_ProblemBlock" data-course-id="course-v1:MITx+6.005.1x+3T2016" data-graded="True" data-init="XBlockToXModuleShim" data-request-token="9dc66f4a223711f0978c16ffcd2b1d4d" data-runtime-version="1" data-block-type="problem" data-usage-id="block-v1:MITx+6.005.1x+3T2016+type@problem+block@03-partitioning-a-string" data-runtime-class="LmsRuntime" data-has-score="True">
<script type="json/xblock-args" class="xblock-json-init-args">
{"xmodule-type": "Problem"}
</script>
<div id="problem_03-partitioning-a-string" class="problems-wrapper" role="group"
aria-labelledby="03-partitioning-a-string-problem-title"
data-problem-id="block-v1:MITx+6.005.1x+3T2016+type@problem+block@03-partitioning-a-string" data-url="/courses/course-v1:MITx+6.005.1x+3T2016/xblock/block-v1:MITx+6.005.1x+3T2016+type@problem+block@03-partitioning-a-string/handler/xmodule_handler"
data-problem-score="0"
data-problem-total-possible="1"
data-attempts-used="0"
data-content="
<h3 class="hd hd-3 problem-header" id="03-partitioning-a-string-problem-title" aria-describedby="block-v1:MITx+6.005.1x+3T2016+type@problem+block@03-partitioning-a-string-problem-progress" tabindex="-1">
partitioning, part 2
</h3>
<div class="problem-progress" id="block-v1:MITx+6.005.1x+3T2016+type@problem+block@03-partitioning-a-string-problem-progress"></div>
<div class="problem">
<div>
<p>Which of the following are reasonable partitions for the text parameter? Check all that apply.</p>
<div class="wrapper-problem-response" tabindex="-1" aria-label="Question 1" role="group"><div class="choicegroup capa_inputtype" id="inputtype_03-partitioning-a-string_2_1">
<fieldset aria-describedby="status_03-partitioning-a-string_2_1">
<div class="field">
<input type="checkbox" name="input_03-partitioning-a-string_2_1[]" id="input_03-partitioning-a-string_2_1_choice_0" class="field-input input-checkbox" value="choice_0"/><label id="03-partitioning-a-string_2_1-choice_0-label" for="input_03-partitioning-a-string_2_1_choice_0" class="response-label field-label label-inline" aria-describedby="status_03-partitioning-a-string_2_1"> text contains some letters; text contains no letters, but some numbers; text contains neither letters nor numbers
</label>
</div>
<div class="field">
<input type="checkbox" name="input_03-partitioning-a-string_2_1[]" id="input_03-partitioning-a-string_2_1_choice_1" class="field-input input-checkbox" value="choice_1"/><label id="03-partitioning-a-string_2_1-choice_1-label" for="input_03-partitioning-a-string_2_1_choice_1" class="response-label field-label label-inline" aria-describedby="status_03-partitioning-a-string_2_1"> text.length() = 0; text.length() &gt; 0
</label>
</div>
<div class="field">
<input type="checkbox" name="input_03-partitioning-a-string_2_1[]" id="input_03-partitioning-a-string_2_1_choice_2" class="field-input input-checkbox" value="choice_2"/><label id="03-partitioning-a-string_2_1-choice_2-label" for="input_03-partitioning-a-string_2_1_choice_2" class="response-label field-label label-inline" aria-describedby="status_03-partitioning-a-string_2_1"> text.length() = 0; text.length()-start is odd; text.length()-start is even
</label>
</div>
<div class="field">
<input type="checkbox" name="input_03-partitioning-a-string_2_1[]" id="input_03-partitioning-a-string_2_1_choice_3" class="field-input input-checkbox" value="choice_3"/><label id="03-partitioning-a-string_2_1-choice_3-label" for="input_03-partitioning-a-string_2_1_choice_3" class="response-label field-label label-inline" aria-describedby="status_03-partitioning-a-string_2_1"> text is every possible string from length 0 to 100
</label>
</div>
<span id="answer_03-partitioning-a-string_2_1"/>
</fieldset>
<div class="indicator-container">
<span class="status unanswered" id="status_03-partitioning-a-string_2_1" data-tooltip="Not yet answered.">
<span class="sr">unanswered</span><span class="status-icon" aria-hidden="true"/>
</span>
</div>
</div></div>
<div class="solution-span">
<span id="solution_03-partitioning-a-string_solution_1"/>
</div></div>
<div class="action">
<input type="hidden" name="problem_id" value="partitioning, part 2" />
<div class="submit-attempt-container">
<button type="button" class="submit btn-brand" data-submitting="Submitting" data-value="Submit" data-should-enable-submit-button="True" aria-describedby="submission_feedback_03-partitioning-a-string" >
<span class="submit-label">Submit</span>
</button>
<div class="submission-feedback" id="submission_feedback_03-partitioning-a-string">
<span class="sr">Some problems have options such as save, reset, hints, or show answer. These options follow the Submit button.</span>
</div>
</div>
<div class="problem-action-buttons-wrapper">
</div>
</div>
<div class="notification warning notification-gentle-alert
is-hidden"
tabindex="-1">
<span class="icon fa fa-exclamation-circle" aria-hidden="true"></span>
<span class="notification-message" aria-describedby="03-partitioning-a-string-problem-title">
</span>
<div class="notification-btn-wrapper">
<button type="button" class="btn btn-default btn-small notification-btn review-btn sr">Review</button>
</div>
</div>
<div class="notification warning notification-save
is-hidden"
tabindex="-1">
<span class="icon fa fa-save" aria-hidden="true"></span>
<span class="notification-message" aria-describedby="03-partitioning-a-string-problem-title">None
</span>
<div class="notification-btn-wrapper">
<button type="button" class="btn btn-default btn-small notification-btn review-btn sr">Review</button>
</div>
</div>
<div class="notification general notification-show-answer
is-hidden"
tabindex="-1">
<span class="icon fa fa-info-circle" aria-hidden="true"></span>
<span class="notification-message" aria-describedby="03-partitioning-a-string-problem-title">Answers are displayed within the problem
</span>
<div class="notification-btn-wrapper">
<button type="button" class="btn btn-default btn-small notification-btn review-btn sr">Review</button>
</div>
</div>
</div>
"
data-graded="True">
<p class="loading-spinner">
<i class="fa fa-spinner fa-pulse fa-2x fa-fw"></i>
<span class="sr">Loading…</span>
</p>
</div>
</div>
</div>
</div>
</div>
<div class="xblock xblock-public_view xblock-public_view-vertical" data-course-id="course-v1:MITx+6.005.1x+3T2016" data-graded="True" data-init="VerticalStudentView" data-request-token="9dc66f4a223711f0978c16ffcd2b1d4d" data-runtime-version="1" data-block-type="vertical" data-usage-id="block-v1:MITx+6.005.1x+3T2016+type@vertical+block@vertical-blackbox-and-whitebox-testing" data-runtime-class="LmsRuntime" data-has-score="False">
<h2 class="hd hd-2 unit-title">Blackbox and Whitebox Testing</h2>
<div class="vert-mod">
<div class="vert vert-0" data-id="block-v1:MITx+6.005.1x+3T2016+type@video+block@video_c14e8bd3e132">
<div class="xblock xblock-public_view xblock-public_view-video xmodule_display xmodule_VideoBlock" data-course-id="course-v1:MITx+6.005.1x+3T2016" data-graded="True" data-init="XBlockToXModuleShim" data-request-token="9dc66f4a223711f0978c16ffcd2b1d4d" data-runtime-version="1" data-block-type="video" data-usage-id="block-v1:MITx+6.005.1x+3T2016+type@video+block@video_c14e8bd3e132" data-runtime-class="LmsRuntime" data-has-score="False">
<script type="json/xblock-args" class="xblock-json-init-args">
{"xmodule-type": "Video"}
</script>
<h3 class="hd hd-2">Video</h3>
<div
id="video_video_c14e8bd3e132"
class="video closed"
data-metadata='{"publishCompletionUrl": "/courses/course-v1:MITx+6.005.1x+3T2016/xblock/block-v1:MITx+6.005.1x+3T2016+type@video+block@video_c14e8bd3e132/handler/publish_completion", "duration": 128.04, "transcriptLanguage": "en", "ytTestTimeout": 1500, "prioritizeHls": false, "generalSpeed": 1.0, "sources": ["https://d2f1egay8yehza.cloudfront.net/MIT600512016-V002400_DTH.mp4", "https://d2f1egay8yehza.cloudfront.net/MIT600512016-V002400/MIT600512016-V002400.m3u8"], "captionDataDir": null, "autoAdvance": false, "poster": null, "autohideHtml5": false, "speed": null, "transcriptTranslationUrl": "/courses/course-v1:MITx+6.005.1x+3T2016/xblock/block-v1:MITx+6.005.1x+3T2016+type@video+block@video_c14e8bd3e132/handler/transcript/translation/__lang__", "recordedYoutubeIsAvailable": true, "completionEnabled": false, "end": 0.0, "ytMetadataEndpoint": "", "completionPercentage": 0.95, "savedVideoPosition": 0.0, "lmsRootURL": "https://openlearninglibrary.mit.edu", "saveStateEnabled": false, "start": 0.0, "streams": "1.00:PasGqcpHe74", "transcriptAvailableTranslationsUrl": "/courses/course-v1:MITx+6.005.1x+3T2016/xblock/block-v1:MITx+6.005.1x+3T2016+type@video+block@video_c14e8bd3e132/handler/transcript/available_translations", "autoplay": false, "showCaptions": "true", "transcriptLanguages": {"en": "English"}, "saveStateUrl": "/courses/course-v1:MITx+6.005.1x+3T2016/xblock/block-v1:MITx+6.005.1x+3T2016+type@video+block@video_c14e8bd3e132/handler/xmodule_handler/save_user_state", "ytApiUrl": "https://www.youtube.com/iframe_api"}'
data-bumper-metadata='null'
data-autoadvance-enabled="False"
data-poster='null'
tabindex="-1"
>
<div class="focus_grabber first"></div>
<div class="tc-wrapper">
<div class="video-wrapper">
<span tabindex="0" class="spinner" aria-hidden="false" aria-label="Loading video player"></span>
<span tabindex="-1" class="btn-play fa fa-youtube-play fa-2x is-hidden" aria-hidden="true" aria-label="Play video"></span>
<div class="video-player-pre"></div>
<div class="video-player">
<div id="video_c14e8bd3e132"></div>
<h4 class="hd hd-4 video-error is-hidden">No playable video sources found.</h4>
<h4 class="hd hd-4 video-hls-error is-hidden">
Your browser does not support this video format. Try using a different browser.
</h4>
</div>
<div class="video-player-post"></div>
<div class="closed-captions"></div>
<div class="video-controls is-hidden">
<div>
<div class="vcr"><div class="vidtime">0:00 / 0:00</div></div>
<div class="secondary-controls"></div>
</div>
</div>
</div>
</div>
<div class="focus_grabber last"></div>
<h3 class="hd hd-4 downloads-heading sr" id="video-download-transcripts_video_c14e8bd3e132">Downloads and transcripts</h3>
<div class="wrapper-downloads" role="region" aria-labelledby="video-download-transcripts_video_c14e8bd3e132">
<div class="wrapper-download-transcripts">
<h4 class="hd hd-5">Transcripts</h4>
<ul class="list-download-transcripts">
<li class="transcript-option">
<a class="btn btn-link" href="/courses/course-v1:MITx+6.005.1x+3T2016/xblock/block-v1:MITx+6.005.1x+3T2016+type@video+block@video_c14e8bd3e132/handler/transcript/download" data-value="srt">Download SubRip (.srt) file</a>
</li>
<li class="transcript-option">
<a class="btn btn-link" href="/courses/course-v1:MITx+6.005.1x+3T2016/xblock/block-v1:MITx+6.005.1x+3T2016+type@video+block@video_c14e8bd3e132/handler/transcript/download" data-value="txt">Download Text (.txt) file</a>
</li>
</ul>
</div>
</div>
</div>
</div>
</div>
<div class="vert vert-1" data-id="block-v1:MITx+6.005.1x+3T2016+type@html+block@html_473c01ca9bcf">
<div class="xblock xblock-public_view xblock-public_view-html xmodule_display xmodule_HtmlBlock" data-course-id="course-v1:MITx+6.005.1x+3T2016" data-graded="True" data-init="XBlockToXModuleShim" data-request-token="9dc66f4a223711f0978c16ffcd2b1d4d" data-runtime-version="1" data-block-type="html" data-usage-id="block-v1:MITx+6.005.1x+3T2016+type@html+block@html_473c01ca9bcf" data-runtime-class="LmsRuntime" data-has-score="False">
<script type="json/xblock-args" class="xblock-json-init-args">
{"xmodule-type": "HTMLModule"}
</script>
<link href="/assets/courseware/v1/9fab367942e94f98d32835b3ef4df11d/asset-v1:MITx+6.005.1x+3T2016+type@asset+block/prism-edx-v1.css" rel="stylesheet" type="text/css" />
<h2 id="blackbox_and_whitebox_testing">Blackbox and Whitebox Testing</h2>
<div data-outline="blackbox_and_whitebox_testing">
<p>Recall from above that the <em>specification</em> is the description of the function's behavior — the types of parameters, type of return value, and constraints and relationships between them.</p>
<p><strong>Blackbox testing</strong> means choosing test cases only from the specification, not the implementation of the function. That's what we've been doing in our examples so far. We partitioned and looked for boundaries in <code>multiply</code> and <code>max</code> without looking at the actual code for these functions.</p>
<p><strong>Whitebox testing</strong> (also called glass box testing) means choosing test cases with knowledge of how the function is actually implemented. For example, if the implementation selects different algorithms depending on the input, then you should partition according to those domains. If the implementation keeps an internal cache that remembers the answers to previous inputs, then you should test repeated inputs.</p>
<p>When doing whitebox testing, you must take care that your test cases don't <em>require</em> specific implementation behavior that isn't specifically called for by the spec. For example, if the spec says “throws an exception if the input is poorly formatted,” then your test shouldn't check <em>specifically</em> for a NullPointerException just because that's what the current implementation does. The specification in this case allows <em>any</em> exception to be thrown, so your test case should likewise be general to preserve the implementor's freedom. We'll have much more to say about this in the class on specs.</p>
</div>
</div>
</div>
</div>
</div>
<div class="xblock xblock-public_view xblock-public_view-vertical" data-course-id="course-v1:MITx+6.005.1x+3T2016" data-graded="True" data-init="VerticalStudentView" data-request-token="9dc66f4a223711f0978c16ffcd2b1d4d" data-runtime-version="1" data-block-type="vertical" data-usage-id="block-v1:MITx+6.005.1x+3T2016+type@vertical+block@vertical_Questions_3a8167dcb1a8" data-runtime-class="LmsRuntime" data-has-score="False">
<h2 class="hd hd-2 unit-title">Questions</h2>
<div class="vert-mod">
<div class="vert vert-0" data-id="block-v1:MITx+6.005.1x+3T2016+type@html+block@html_fff67ba8819a">
<div class="xblock xblock-public_view xblock-public_view-html xmodule_display xmodule_HtmlBlock" data-course-id="course-v1:MITx+6.005.1x+3T2016" data-graded="True" data-init="XBlockToXModuleShim" data-request-token="9dc66f4a223711f0978c16ffcd2b1d4d" data-runtime-version="1" data-block-type="html" data-usage-id="block-v1:MITx+6.005.1x+3T2016+type@html+block@html_fff67ba8819a" data-runtime-class="LmsRuntime" data-has-score="False">
<script type="json/xblock-args" class="xblock-json-init-args">
{"xmodule-type": "HTMLModule"}
</script>
<link href="/assets/courseware/v1/9fab367942e94f98d32835b3ef4df11d/asset-v1:MITx+6.005.1x+3T2016+type@asset+block/prism-edx-v1.css" rel="stylesheet" type="text/css" />
<link href="/assets/courseware/v1/9fab367942e94f98d32835b3ef4df11d/asset-v1:MITx+6.005.1x+3T2016+type@asset+block/prism-edx-v1.css" rel="stylesheet" type="text/css" />
<script src="/assets/courseware/v1/3e6443fb95285d2dc06e8ffc448b9bdf/asset-v1:MITx+6.005.1x+3T2016+type@asset+block/prism.js"></script>
<script src="/assets/courseware/v1/2ba76f8bdfef4e2d45e31a3dc5208470/asset-v1:MITx+6.005.1x+3T2016+type@asset+block/edx-script-v1.js"></script>
</div>
</div>
<div class="vert vert-1" data-id="block-v1:MITx+6.005.1x+3T2016+type@problem+block@03-blackbox-and-whitebox-testing">
<div class="xblock xblock-public_view xblock-public_view-problem xmodule_display xmodule_ProblemBlock" data-course-id="course-v1:MITx+6.005.1x+3T2016" data-graded="True" data-init="XBlockToXModuleShim" data-request-token="9dc66f4a223711f0978c16ffcd2b1d4d" data-runtime-version="1" data-block-type="problem" data-usage-id="block-v1:MITx+6.005.1x+3T2016+type@problem+block@03-blackbox-and-whitebox-testing" data-runtime-class="LmsRuntime" data-has-score="True">
<script type="json/xblock-args" class="xblock-json-init-args">
{"xmodule-type": "Problem"}
</script>
<div id="problem_03-blackbox-and-whitebox-testing" class="problems-wrapper" role="group"
aria-labelledby="03-blackbox-and-whitebox-testing-problem-title"
data-problem-id="block-v1:MITx+6.005.1x+3T2016+type@problem+block@03-blackbox-and-whitebox-testing" data-url="/courses/course-v1:MITx+6.005.1x+3T2016/xblock/block-v1:MITx+6.005.1x+3T2016+type@problem+block@03-blackbox-and-whitebox-testing/handler/xmodule_handler"
data-problem-score="0"
data-problem-total-possible="1"
data-attempts-used="0"
data-content="
<h3 class="hd hd-3 problem-header" id="03-blackbox-and-whitebox-testing-problem-title" aria-describedby="block-v1:MITx+6.005.1x+3T2016+type@problem+block@03-blackbox-and-whitebox-testing-problem-progress" tabindex="-1">
blackbox and whitebox testing
</h3>
<div class="problem-progress" id="block-v1:MITx+6.005.1x+3T2016+type@problem+block@03-blackbox-and-whitebox-testing-problem-progress"></div>
<div class="problem">
<div>
<p>Consider the following function:</p>
<pre class="code">
/**
* Sort a list of integers in nondecreasing order. Modifies the list so that
* values.get(i) &lt;= values.get(i+1) for all 0&lt;=i&lt;values.length()-1
*/
public static void sort(List&lt;Integer&gt; values) {
// choose a good algorithm for the size of the list
if (values.length() &lt; 10) {
radixSort(values);
} else if (values.length() &lt; 1000*1000*1000) {
quickSort(values);
} else {
mergeSort(values);
}
}
</pre>
<div class="wrapper-problem-response" tabindex="-1" aria-label="Question 1" role="group"><div class="choicegroup capa_inputtype" id="inputtype_03-blackbox-and-whitebox-testing_2_1">
<fieldset aria-describedby="status_03-blackbox-and-whitebox-testing_2_1">
<legend id="03-blackbox-and-whitebox-testing_2_1-legend" class="response-fieldset-legend field-group-hd">Which of the following test cases are likely to be boundary values produced by white box testing?</legend>
<div class="field">
<input type="checkbox" name="input_03-blackbox-and-whitebox-testing_2_1[]" id="input_03-blackbox-and-whitebox-testing_2_1_choice_0" class="field-input input-checkbox" value="choice_0"/><label id="03-blackbox-and-whitebox-testing_2_1-choice_0-label" for="input_03-blackbox-and-whitebox-testing_2_1_choice_0" class="response-label field-label label-inline" aria-describedby="status_03-blackbox-and-whitebox-testing_2_1"> the empty list
</label>
</div>
<div class="field">
<input type="checkbox" name="input_03-blackbox-and-whitebox-testing_2_1[]" id="input_03-blackbox-and-whitebox-testing_2_1_choice_1" class="field-input input-checkbox" value="choice_1"/><label id="03-blackbox-and-whitebox-testing_2_1-choice_1-label" for="input_03-blackbox-and-whitebox-testing_2_1_choice_1" class="response-label field-label label-inline" aria-describedby="status_03-blackbox-and-whitebox-testing_2_1"> 1, 2, 3
</label>
</div>
<div class="field">
<input type="checkbox" name="input_03-blackbox-and-whitebox-testing_2_1[]" id="input_03-blackbox-and-whitebox-testing_2_1_choice_2" class="field-input input-checkbox" value="choice_2"/><label id="03-blackbox-and-whitebox-testing_2_1-choice_2-label" for="input_03-blackbox-and-whitebox-testing_2_1_choice_2" class="response-label field-label label-inline" aria-describedby="status_03-blackbox-and-whitebox-testing_2_1"> 9, 8, 7, 6, 5, 4, 3, 2, 1, 0
</label>
</div>
<div class="field">
<input type="checkbox" name="input_03-blackbox-and-whitebox-testing_2_1[]" id="input_03-blackbox-and-whitebox-testing_2_1_choice_3" class="field-input input-checkbox" value="choice_3"/><label id="03-blackbox-and-whitebox-testing_2_1-choice_3-label" for="input_03-blackbox-and-whitebox-testing_2_1_choice_3" class="response-label field-label label-inline" aria-describedby="status_03-blackbox-and-whitebox-testing_2_1"> 0, 0, 1, 0, 0, 0, 0
</label>
</div>
<span id="answer_03-blackbox-and-whitebox-testing_2_1"/>
</fieldset>
<div class="indicator-container">
<span class="status unanswered" id="status_03-blackbox-and-whitebox-testing_2_1" data-tooltip="Not yet answered.">
<span class="sr">unanswered</span><span class="status-icon" aria-hidden="true"/>
</span>
</div>
</div></div>
<div class="solution-span">
<span id="solution_03-blackbox-and-whitebox-testing_solution_1"/>
</div></div>
<div class="action">
<input type="hidden" name="problem_id" value="blackbox and whitebox testing" />
<div class="submit-attempt-container">
<button type="button" class="submit btn-brand" data-submitting="Submitting" data-value="Submit" data-should-enable-submit-button="True" aria-describedby="submission_feedback_03-blackbox-and-whitebox-testing" >
<span class="submit-label">Submit</span>
</button>
<div class="submission-feedback" id="submission_feedback_03-blackbox-and-whitebox-testing">
<span class="sr">Some problems have options such as save, reset, hints, or show answer. These options follow the Submit button.</span>
</div>
</div>
<div class="problem-action-buttons-wrapper">
</div>
</div>
<div class="notification warning notification-gentle-alert
is-hidden"
tabindex="-1">
<span class="icon fa fa-exclamation-circle" aria-hidden="true"></span>
<span class="notification-message" aria-describedby="03-blackbox-and-whitebox-testing-problem-title">
</span>
<div class="notification-btn-wrapper">
<button type="button" class="btn btn-default btn-small notification-btn review-btn sr">Review</button>
</div>
</div>
<div class="notification warning notification-save
is-hidden"
tabindex="-1">
<span class="icon fa fa-save" aria-hidden="true"></span>
<span class="notification-message" aria-describedby="03-blackbox-and-whitebox-testing-problem-title">None
</span>
<div class="notification-btn-wrapper">
<button type="button" class="btn btn-default btn-small notification-btn review-btn sr">Review</button>
</div>
</div>
<div class="notification general notification-show-answer
is-hidden"
tabindex="-1">
<span class="icon fa fa-info-circle" aria-hidden="true"></span>
<span class="notification-message" aria-describedby="03-blackbox-and-whitebox-testing-problem-title">Answers are displayed within the problem
</span>
<div class="notification-btn-wrapper">
<button type="button" class="btn btn-default btn-small notification-btn review-btn sr">Review</button>
</div>
</div>
</div>
"
data-graded="True">
<p class="loading-spinner">
<i class="fa fa-spinner fa-pulse fa-2x fa-fw"></i>
<span class="sr">Loading…</span>
</p>
</div>
</div>
</div>
</div>
</div>
<div class="xblock xblock-public_view xblock-public_view-vertical" data-course-id="course-v1:MITx+6.005.1x+3T2016" data-graded="True" data-init="VerticalStudentView" data-request-token="9dc66f4a223711f0978c16ffcd2b1d4d" data-runtime-version="1" data-block-type="vertical" data-usage-id="block-v1:MITx+6.005.1x+3T2016+type@vertical+block@vertical-documenting-your-tsting-strategy" data-runtime-class="LmsRuntime" data-has-score="False">
<h2 class="hd hd-2 unit-title">Documenting Your Testing Strategy</h2>
<div class="vert-mod">
<div class="vert vert-0" data-id="block-v1:MITx+6.005.1x+3T2016+type@video+block@video_ca3eca34cd0d">
<div class="xblock xblock-public_view xblock-public_view-video xmodule_display xmodule_VideoBlock" data-course-id="course-v1:MITx+6.005.1x+3T2016" data-graded="True" data-init="XBlockToXModuleShim" data-request-token="9dc66f4a223711f0978c16ffcd2b1d4d" data-runtime-version="1" data-block-type="video" data-usage-id="block-v1:MITx+6.005.1x+3T2016+type@video+block@video_ca3eca34cd0d" data-runtime-class="LmsRuntime" data-has-score="False">
<script type="json/xblock-args" class="xblock-json-init-args">
{"xmodule-type": "Video"}
</script>
<h3 class="hd hd-2">Video</h3>
<div
id="video_video_ca3eca34cd0d"
class="video closed"
data-metadata='{"publishCompletionUrl": "/courses/course-v1:MITx+6.005.1x+3T2016/xblock/block-v1:MITx+6.005.1x+3T2016+type@video+block@video_ca3eca34cd0d/handler/publish_completion", "duration": 219.13, "transcriptLanguage": "en", "ytTestTimeout": 1500, "prioritizeHls": false, "generalSpeed": 1.0, "sources": ["https://d2f1egay8yehza.cloudfront.net/MIT600512016-V001900_DTH.mp4", "https://d2f1egay8yehza.cloudfront.net/MIT600512016-V001900/MIT600512016-V001900.m3u8"], "captionDataDir": null, "autoAdvance": false, "poster": null, "autohideHtml5": false, "speed": null, "transcriptTranslationUrl": "/courses/course-v1:MITx+6.005.1x+3T2016/xblock/block-v1:MITx+6.005.1x+3T2016+type@video+block@video_ca3eca34cd0d/handler/transcript/translation/__lang__", "recordedYoutubeIsAvailable": true, "completionEnabled": false, "end": 0.0, "ytMetadataEndpoint": "", "completionPercentage": 0.95, "savedVideoPosition": 0.0, "lmsRootURL": "https://openlearninglibrary.mit.edu", "saveStateEnabled": false, "start": 0.0, "streams": "1.00:29mmSomPQKk", "transcriptAvailableTranslationsUrl": "/courses/course-v1:MITx+6.005.1x+3T2016/xblock/block-v1:MITx+6.005.1x+3T2016+type@video+block@video_ca3eca34cd0d/handler/transcript/available_translations", "autoplay": false, "showCaptions": "true", "transcriptLanguages": {"en": "English"}, "saveStateUrl": "/courses/course-v1:MITx+6.005.1x+3T2016/xblock/block-v1:MITx+6.005.1x+3T2016+type@video+block@video_ca3eca34cd0d/handler/xmodule_handler/save_user_state", "ytApiUrl": "https://www.youtube.com/iframe_api"}'
data-bumper-metadata='null'
data-autoadvance-enabled="False"
data-poster='null'
tabindex="-1"
>
<div class="focus_grabber first"></div>
<div class="tc-wrapper">
<div class="video-wrapper">
<span tabindex="0" class="spinner" aria-hidden="false" aria-label="Loading video player"></span>
<span tabindex="-1" class="btn-play fa fa-youtube-play fa-2x is-hidden" aria-hidden="true" aria-label="Play video"></span>
<div class="video-player-pre"></div>
<div class="video-player">
<div id="video_ca3eca34cd0d"></div>
<h4 class="hd hd-4 video-error is-hidden">No playable video sources found.</h4>
<h4 class="hd hd-4 video-hls-error is-hidden">
Your browser does not support this video format. Try using a different browser.
</h4>
</div>
<div class="video-player-post"></div>
<div class="closed-captions"></div>
<div class="video-controls is-hidden">
<div>
<div class="vcr"><div class="vidtime">0:00 / 0:00</div></div>
<div class="secondary-controls"></div>
</div>
</div>
</div>
</div>
<div class="focus_grabber last"></div>
<h3 class="hd hd-4 downloads-heading sr" id="video-download-transcripts_video_ca3eca34cd0d">Downloads and transcripts</h3>
<div class="wrapper-downloads" role="region" aria-labelledby="video-download-transcripts_video_ca3eca34cd0d">
<div class="wrapper-download-transcripts">
<h4 class="hd hd-5">Transcripts</h4>
<ul class="list-download-transcripts">
<li class="transcript-option">
<a class="btn btn-link" href="/courses/course-v1:MITx+6.005.1x+3T2016/xblock/block-v1:MITx+6.005.1x+3T2016+type@video+block@video_ca3eca34cd0d/handler/transcript/download" data-value="srt">Download SubRip (.srt) file</a>
</li>
<li class="transcript-option">
<a class="btn btn-link" href="/courses/course-v1:MITx+6.005.1x+3T2016/xblock/block-v1:MITx+6.005.1x+3T2016+type@video+block@video_ca3eca34cd0d/handler/transcript/download" data-value="txt">Download Text (.txt) file</a>
</li>
</ul>
</div>
</div>
</div>
</div>
</div>
<div class="vert vert-1" data-id="block-v1:MITx+6.005.1x+3T2016+type@html+block@html_9ed22724fbe1">
<div class="xblock xblock-public_view xblock-public_view-html xmodule_display xmodule_HtmlBlock" data-course-id="course-v1:MITx+6.005.1x+3T2016" data-graded="True" data-init="XBlockToXModuleShim" data-request-token="9dc66f4a223711f0978c16ffcd2b1d4d" data-runtime-version="1" data-block-type="html" data-usage-id="block-v1:MITx+6.005.1x+3T2016+type@html+block@html_9ed22724fbe1" data-runtime-class="LmsRuntime" data-has-score="False">
<script type="json/xblock-args" class="xblock-json-init-args">
{"xmodule-type": "HTMLModule"}
</script>
<link href="/assets/courseware/v1/9fab367942e94f98d32835b3ef4df11d/asset-v1:MITx+6.005.1x+3T2016+type@asset+block/prism-edx-v1.css" rel="stylesheet" type="text/css" />
<h2 id="documenting_your_testing_strategy">Documenting Your Testing Strategy</h2>
<div data-outline="documenting_your_testing_strategy"><p>For the example function on the left, on the right is how we can document the testing strategy we worked on in the <a href="/courses/course-v1:MITx+6.005.1x+3T2016/jump_to_id/vertical-partitioning-questions">partitioning exercises earlier in this reading</a>.
The strategy also addresses some boundary values we didn’t consider before.</p><table class="side-by-side pull-margin"><tbody><tr><td><pre><code class="language-java hljs"><span class="hljs-comment handout-javadoc-comment">/**
* Reverses the end of a string.
*
* For example:
* reverseEnd("Hello, world", 5)
* returns "Hellodlrow ,"
*
* With start == 0, reverses the entire text.
* With start == text.length(), reverses nothing.
*
* <span class="hljs-doctag">@param</span> text non-null String that will have
* its end reversed
* <span class="hljs-doctag">@param</span> start the index at which the
* remainder of the input is
* reversed, requires 0 <=
* start <= text.length()
* <span class="hljs-doctag">@return</span> input text with the substring from
* start to the end of the string
* reversed
*/</span>
<span class="hljs-function"><span class="hljs-keyword">static</span> String <span class="hljs-title">reverseEnd</span><span class="hljs-params">(String text, <span class="hljs-keyword">int</span> start)</span></span></code></pre></td><td><p>Document the strategy at the top of the test class:</p>
<pre><code class="language-java hljs"><span class="hljs-comment">/*
* Testing strategy
*
* Partition the inputs as follows:
* text.length(): 0, 1, > 1
* start: 0, 1, 1 < start < text.length(),
* text.length() - 1, text.length()
* text.length()-start: 0, 1, even > 1, odd > 1
*
* Include even- and odd-length reversals because
* only odd has a middle element that doesn't move.
*
* Exhaustive Cartesian coverage of partitions.
*/</span></code></pre>
<p>Document how each test case was chosen, including white box tests:</p>
<pre><code class="language-java hljs"><span class="hljs-comment">// covers test.length() = 0,</span>
<span class="hljs-comment">// start = 0 = text.length(),</span>
<span class="hljs-comment">// text.length()-start = 0</span>
<span class="hljs-meta">@Test</span> <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">testEmpty</span><span class="hljs-params">()</span> </span>{
assertEquals(<span class="hljs-string">""</span>, reverseEnd(<span class="hljs-string">""</span>, <span class="hljs-number">0</span>));
}
<span class="hljs-comment">// ... other test cases ...</span></code></pre></td></tr></tbody></table></div>
<h2 id="coverage">Coverage</h2>
<div data-outline="coverage">
<p>One way to judge a test suite is to ask how thoroughly it exercises the program. This notion is called <em>coverage</em>. There are three common kinds of coverage:</p>
<ul>
<li><strong>Statement coverage</strong>: is every statement run by some test case?</li>
<li><strong>Branch coverage</strong>: for every <code>if</code> or <code>while</code> statement in the program, are both the true and the false direction taken by some test case?</li>
<li><strong>Path coverage</strong>: is every possible combination of branches — every path through the program — taken by some test case?</li>
</ul>
<p>Branch coverage is stronger (requires more tests to achieve) than statement coverage, and path coverage is stronger than branch coverage. In industry, 100% statement coverage is a common goal, but even that is rarely achieved due to unreachable defensive code (like “should never get here” assertions). 100% branch coverage is highly desirable, and safety critical industry code has even more arduous criteria (e.g., “MCDC,” modified decision/condition coverage). Unfortunately 100% path coverage is infeasible, requiring exponential-size test suites to achieve.</p>
<p>A standard approach to testing is to add tests until the test suite achieves adequate statement coverage: i.e., so that every reachable statement in the program is executed by at least one test case. In practice, statement coverage is usually measured by a code coverage tool, which counts the number of times each statement is run by your test suite. With such a tool, white box testing is easy; you just measure the coverage of your black box tests, and add more test cases until all important statements are logged as executed. </p>
<div class="panel panel-figure pull-right pull-margin">
<a href="/assets/courseware/v1/e066db8fc2d22d006824cc08975e3dcb/asset-v1:MITx+6.005.1x+3T2016+type@asset+block/03-eclemma.png"><img src="/assets/courseware/v1/e066db8fc2d22d006824cc08975e3dcb/asset-v1:MITx+6.005.1x+3T2016+type@asset+block/03-eclemma.png" alt="EclEmma code coverage tool for Eclipse" width="450"></img></a>
</div>
<p>A good code coverage tool for Eclipse is <a href="http://www.eclemma.org/">EclEmma</a>, shown on the right.</p>
<p>Notice how lines that have been executed by the test suite are colored green, and lines not yet covered are red. If you saw this result from your coverage tool, your next step would be to come up with a test case that causes the body of the while loop to execute, and add it to your test suite so that the red lines become green.</p>
</div>
</div>
</div>
</div>
</div>
<div class="xblock xblock-public_view xblock-public_view-vertical" data-course-id="course-v1:MITx+6.005.1x+3T2016" data-graded="True" data-init="VerticalStudentView" data-request-token="9dc66f4a223711f0978c16ffcd2b1d4d" data-runtime-version="1" data-block-type="vertical" data-usage-id="block-v1:MITx+6.005.1x+3T2016+type@vertical+block@vertical_Questions_f1ca6866e089" data-runtime-class="LmsRuntime" data-has-score="False">
<h2 class="hd hd-2 unit-title">Questions</h2>
<div class="vert-mod">
<div class="vert vert-0" data-id="block-v1:MITx+6.005.1x+3T2016+type@html+block@html_fff67ba8819a">
<div class="xblock xblock-public_view xblock-public_view-html xmodule_display xmodule_HtmlBlock" data-course-id="course-v1:MITx+6.005.1x+3T2016" data-graded="True" data-init="XBlockToXModuleShim" data-request-token="9dc66f4a223711f0978c16ffcd2b1d4d" data-runtime-version="1" data-block-type="html" data-usage-id="block-v1:MITx+6.005.1x+3T2016+type@html+block@html_fff67ba8819a" data-runtime-class="LmsRuntime" data-has-score="False">
<script type="json/xblock-args" class="xblock-json-init-args">
{"xmodule-type": "HTMLModule"}
</script>
<link href="/assets/courseware/v1/9fab367942e94f98d32835b3ef4df11d/asset-v1:MITx+6.005.1x+3T2016+type@asset+block/prism-edx-v1.css" rel="stylesheet" type="text/css" />
<link href="/assets/courseware/v1/9fab367942e94f98d32835b3ef4df11d/asset-v1:MITx+6.005.1x+3T2016+type@asset+block/prism-edx-v1.css" rel="stylesheet" type="text/css" />
<script src="/assets/courseware/v1/3e6443fb95285d2dc06e8ffc448b9bdf/asset-v1:MITx+6.005.1x+3T2016+type@asset+block/prism.js"></script>
<script src="/assets/courseware/v1/2ba76f8bdfef4e2d45e31a3dc5208470/asset-v1:MITx+6.005.1x+3T2016+type@asset+block/edx-script-v1.js"></script>
</div>
</div>
<div class="vert vert-1" data-id="block-v1:MITx+6.005.1x+3T2016+type@problem+block@03-coverage">
<div class="xblock xblock-public_view xblock-public_view-problem xmodule_display xmodule_ProblemBlock" data-course-id="course-v1:MITx+6.005.1x+3T2016" data-graded="True" data-init="XBlockToXModuleShim" data-request-token="9dc66f4a223711f0978c16ffcd2b1d4d" data-runtime-version="1" data-block-type="problem" data-usage-id="block-v1:MITx+6.005.1x+3T2016+type@problem+block@03-coverage" data-runtime-class="LmsRuntime" data-has-score="True">
<script type="json/xblock-args" class="xblock-json-init-args">
{"xmodule-type": "Problem"}
</script>
<div id="problem_03-coverage" class="problems-wrapper" role="group"
aria-labelledby="03-coverage-problem-title"
data-problem-id="block-v1:MITx+6.005.1x+3T2016+type@problem+block@03-coverage" data-url="/courses/course-v1:MITx+6.005.1x+3T2016/xblock/block-v1:MITx+6.005.1x+3T2016+type@problem+block@03-coverage/handler/xmodule_handler"
data-problem-score="0"
data-problem-total-possible="3"
data-attempts-used="0"
data-content="
<h3 class="hd hd-3 problem-header" id="03-coverage-problem-title" aria-describedby="block-v1:MITx+6.005.1x+3T2016+type@problem+block@03-coverage-problem-progress" tabindex="-1">
coverage
</h3>
<div class="problem-progress" id="block-v1:MITx+6.005.1x+3T2016+type@problem+block@03-coverage-problem-progress"></div>
<div class="problem">
<div><a href="http://www.eclemma.org/installation.html">Install EclEmma</a> in Eclipse.
<p>Then create a new Java class called Hailstone.java containing this code:</p>
<pre class="code">
public class Hailstone {
public static void main(String[] args) {
int n = 3;
while (n != 1) {
if (n % 2 == 0) {
n = n / 2;
} else {
n = 3 * n + 1;
}
}
}
}
</pre>
<p>Run this class with EclEmma code coverage highlighting turned on, by choosing Run / Coverage As / Java Application.</p>
<p>By changing the initial value of n, you can observe how EclEmma highlights different lines of code differently.</p>
<p>When n=3 initially, what color is the line n = n/2 after execution?</p>
<div class="wrapper-problem-response" tabindex="-1" aria-label="Question 1" role="group"><div class="inputtype option-input ">
<select name="input_03-coverage_2_1" id="input_03-coverage_2_1" aria-describedby="status_03-coverage_2_1">
<option value="option_03-coverage_2_1_dummy_default">Select an option</option>
<option value="green"> green</option>
<option value="yellow"> yellow</option>
<option value="red"> red</option>
<option value="white"> white</option>
</select>
<div class="indicator-container">
<span class="status unanswered" id="status_03-coverage_2_1" data-tooltip="Not yet answered.">
<span class="sr">unanswered</span><span class="status-icon" aria-hidden="true"/>
</span>
</div>
<p class="answer" id="answer_03-coverage_2_1"/>
</div></div>
<div class="solution-span">
<span id="solution_03-coverage_solution_1"/>
</div><p>When n=16 initially, what color is the line n = 3 * n + 1 after execution?</p>
<div class="wrapper-problem-response" tabindex="-1" aria-label="Question 2" role="group"><div class="inputtype option-input ">
<select name="input_03-coverage_3_1" id="input_03-coverage_3_1" aria-describedby="status_03-coverage_3_1">
<option value="option_03-coverage_3_1_dummy_default">Select an option</option>
<option value="green"> green</option>
<option value="yellow"> yellow</option>
<option value="red"> red</option>
<option value="white"> white</option>
</select>
<div class="indicator-container">
<span class="status unanswered" id="status_03-coverage_3_1" data-tooltip="Not yet answered.">
<span class="sr">unanswered</span><span class="status-icon" aria-hidden="true"/>
</span>
</div>
<p class="answer" id="answer_03-coverage_3_1"/>
</div></div>
<div class="solution-span">
<span id="solution_03-coverage_solution_2"/>
</div><p>What initial value of n would make the line while (n != 1) yellow after execution?</p>
<div class="wrapper-problem-response" tabindex="-1" aria-label="Question 3" role="group"><div id="formulaequationinput_03-coverage_4_1" class="inputtype formulaequationinput">
<div class="unanswered">
<input type="text" name="input_03-coverage_4_1" id="input_03-coverage_4_1" data-input-id="03-coverage_4_1" value="" aria-describedby="status_03-coverage_4_1" size="20"/>
<span class="trailing_text" id="trailing_text_03-coverage_4_1"/>
<span class="status unanswered" id="status_03-coverage_4_1" data-tooltip="Not yet answered.">
<span class="sr">unanswered</span><span class="status-icon" aria-hidden="true"/>
</span>
<p id="answer_03-coverage_4_1" class="answer"/>
<div id="input_03-coverage_4_1_preview" class="equation">
\(\)
<img src="/static/images/spinner.bc34f953403f.gif" class="loading" alt="Loading"/>
</div>
</div>
<div class="script_placeholder" data-src="/static/js/capa/src/formula_equation_preview.b1967ab28c31.js"/>
</div></div>
<div class="solution-span">
<span id="solution_03-coverage_solution_3"/>
</div></div>
<div class="action">
<input type="hidden" name="problem_id" value="coverage" />
<div class="submit-attempt-container">
<button type="button" class="submit btn-brand" data-submitting="Submitting" data-value="Submit" data-should-enable-submit-button="True" aria-describedby="submission_feedback_03-coverage" >
<span class="submit-label">Submit</span>
</button>
<div class="submission-feedback" id="submission_feedback_03-coverage">
<span class="sr">Some problems have options such as save, reset, hints, or show answer. These options follow the Submit button.</span>
</div>
</div>
<div class="problem-action-buttons-wrapper">
</div>
</div>
<div class="notification warning notification-gentle-alert
is-hidden"
tabindex="-1">
<span class="icon fa fa-exclamation-circle" aria-hidden="true"></span>
<span class="notification-message" aria-describedby="03-coverage-problem-title">
</span>
<div class="notification-btn-wrapper">
<button type="button" class="btn btn-default btn-small notification-btn review-btn sr">Review</button>
</div>
</div>
<div class="notification warning notification-save
is-hidden"
tabindex="-1">
<span class="icon fa fa-save" aria-hidden="true"></span>
<span class="notification-message" aria-describedby="03-coverage-problem-title">None
</span>
<div class="notification-btn-wrapper">
<button type="button" class="btn btn-default btn-small notification-btn review-btn sr">Review</button>
</div>
</div>
<div class="notification general notification-show-answer
is-hidden"
tabindex="-1">
<span class="icon fa fa-info-circle" aria-hidden="true"></span>
<span class="notification-message" aria-describedby="03-coverage-problem-title">Answers are displayed within the problem
</span>
<div class="notification-btn-wrapper">
<button type="button" class="btn btn-default btn-small notification-btn review-btn sr">Review</button>
</div>
</div>
</div>
"
data-graded="True">
<p class="loading-spinner">
<i class="fa fa-spinner fa-pulse fa-2x fa-fw"></i>
<span class="sr">Loading…</span>
</p>
</div>
</div>
</div>
</div>
</div>
<div class="xblock xblock-public_view xblock-public_view-vertical" data-course-id="course-v1:MITx+6.005.1x+3T2016" data-graded="True" data-init="VerticalStudentView" data-request-token="9dc66f4a223711f0978c16ffcd2b1d4d" data-runtime-version="1" data-block-type="vertical" data-usage-id="block-v1:MITx+6.005.1x+3T2016+type@vertical+block@vertical-unit-testing-and-stubs" data-runtime-class="LmsRuntime" data-has-score="False">
<h2 class="hd hd-2 unit-title">Unit Testing And Stubs</h2>
<div class="vert-mod">
<div class="vert vert-0" data-id="block-v1:MITx+6.005.1x+3T2016+type@video+block@video_9830119cb706">
<div class="xblock xblock-public_view xblock-public_view-video xmodule_display xmodule_VideoBlock" data-course-id="course-v1:MITx+6.005.1x+3T2016" data-graded="True" data-init="XBlockToXModuleShim" data-request-token="9dc66f4a223711f0978c16ffcd2b1d4d" data-runtime-version="1" data-block-type="video" data-usage-id="block-v1:MITx+6.005.1x+3T2016+type@video+block@video_9830119cb706" data-runtime-class="LmsRuntime" data-has-score="False">
<script type="json/xblock-args" class="xblock-json-init-args">
{"xmodule-type": "Video"}
</script>
<h3 class="hd hd-2">Video</h3>
<div
id="video_video_9830119cb706"
class="video closed"
data-metadata='{"publishCompletionUrl": "/courses/course-v1:MITx+6.005.1x+3T2016/xblock/block-v1:MITx+6.005.1x+3T2016+type@video+block@video_9830119cb706/handler/publish_completion", "duration": 341.31, "transcriptLanguage": "en", "ytTestTimeout": 1500, "prioritizeHls": false, "generalSpeed": 1.0, "sources": ["https://d2f1egay8yehza.cloudfront.net/MIT600512016-V001800_DTH.mp4", "https://d2f1egay8yehza.cloudfront.net/MIT600512016-V001800/MIT600512016-V001800.m3u8"], "captionDataDir": null, "autoAdvance": false, "poster": null, "autohideHtml5": false, "speed": null, "transcriptTranslationUrl": "/courses/course-v1:MITx+6.005.1x+3T2016/xblock/block-v1:MITx+6.005.1x+3T2016+type@video+block@video_9830119cb706/handler/transcript/translation/__lang__", "recordedYoutubeIsAvailable": true, "completionEnabled": false, "end": 0.0, "ytMetadataEndpoint": "", "completionPercentage": 0.95, "savedVideoPosition": 0.0, "lmsRootURL": "https://openlearninglibrary.mit.edu", "saveStateEnabled": false, "start": 0.0, "streams": "1.00:ku_7hzB4APo", "transcriptAvailableTranslationsUrl": "/courses/course-v1:MITx+6.005.1x+3T2016/xblock/block-v1:MITx+6.005.1x+3T2016+type@video+block@video_9830119cb706/handler/transcript/available_translations", "autoplay": false, "showCaptions": "true", "transcriptLanguages": {"en": "English"}, "saveStateUrl": "/courses/course-v1:MITx+6.005.1x+3T2016/xblock/block-v1:MITx+6.005.1x+3T2016+type@video+block@video_9830119cb706/handler/xmodule_handler/save_user_state", "ytApiUrl": "https://www.youtube.com/iframe_api"}'
data-bumper-metadata='null'
data-autoadvance-enabled="False"
data-poster='null'
tabindex="-1"
>
<div class="focus_grabber first"></div>
<div class="tc-wrapper">
<div class="video-wrapper">
<span tabindex="0" class="spinner" aria-hidden="false" aria-label="Loading video player"></span>
<span tabindex="-1" class="btn-play fa fa-youtube-play fa-2x is-hidden" aria-hidden="true" aria-label="Play video"></span>
<div class="video-player-pre"></div>
<div class="video-player">
<div id="video_9830119cb706"></div>
<h4 class="hd hd-4 video-error is-hidden">No playable video sources found.</h4>
<h4 class="hd hd-4 video-hls-error is-hidden">
Your browser does not support this video format. Try using a different browser.
</h4>
</div>
<div class="video-player-post"></div>
<div class="closed-captions"></div>
<div class="video-controls is-hidden">
<div>
<div class="vcr"><div class="vidtime">0:00 / 0:00</div></div>
<div class="secondary-controls"></div>
</div>
</div>
</div>
</div>
<div class="focus_grabber last"></div>
<h3 class="hd hd-4 downloads-heading sr" id="video-download-transcripts_video_9830119cb706">Downloads and transcripts</h3>
<div class="wrapper-downloads" role="region" aria-labelledby="video-download-transcripts_video_9830119cb706">
<div class="wrapper-download-transcripts">
<h4 class="hd hd-5">Transcripts</h4>
<ul class="list-download-transcripts">
<li class="transcript-option">
<a class="btn btn-link" href="/courses/course-v1:MITx+6.005.1x+3T2016/xblock/block-v1:MITx+6.005.1x+3T2016+type@video+block@video_9830119cb706/handler/transcript/download" data-value="srt">Download SubRip (.srt) file</a>
</li>
<li class="transcript-option">
<a class="btn btn-link" href="/courses/course-v1:MITx+6.005.1x+3T2016/xblock/block-v1:MITx+6.005.1x+3T2016+type@video+block@video_9830119cb706/handler/transcript/download" data-value="txt">Download Text (.txt) file</a>
</li>
</ul>
</div>
</div>
</div>
</div>
</div>
<div class="vert vert-1" data-id="block-v1:MITx+6.005.1x+3T2016+type@html+block@html_194fc254774c">
<div class="xblock xblock-public_view xblock-public_view-html xmodule_display xmodule_HtmlBlock" data-course-id="course-v1:MITx+6.005.1x+3T2016" data-graded="True" data-init="XBlockToXModuleShim" data-request-token="9dc66f4a223711f0978c16ffcd2b1d4d" data-runtime-version="1" data-block-type="html" data-usage-id="block-v1:MITx+6.005.1x+3T2016+type@html+block@html_194fc254774c" data-runtime-class="LmsRuntime" data-has-score="False">
<script type="json/xblock-args" class="xblock-json-init-args">
{"xmodule-type": "HTMLModule"}
</script>
<link href="/assets/courseware/v1/9fab367942e94f98d32835b3ef4df11d/asset-v1:MITx+6.005.1x+3T2016+type@asset+block/prism-edx-v1.css" rel="stylesheet" type="text/css" />
<h2 id="unit_testing_and_stubs">Unit Testing and Stubs</h2>
<div data-outline="unit_testing_and_stubs">
<p>A well-tested program will have tests for every individual module (where a module is a method or a class) that it contains. A test that tests an individual module, in isolation if possible, is called a <strong>unit test</strong>. Testing modules in isolation leads to much easier debugging. When a unit test for a module fails, you can be more confident that the bug is found in that module, rather than anywhere in the program.</p>
<p>The opposite of a unit test is an <strong>integration test</strong>, which tests a combination of modules, or even the entire program. If all you have are integration tests, then when a test fails, you have to hunt for the bug. It might be anywhere in the program. Integration tests are still important, because a program can fail at the connections between modules. For example, one module may be expecting different inputs than it's actually getting from another module. But if you have a thorough set of unit tests that give you confidence in the correctness of individual modules, then you'll have much less searching to do to find the bug.</p>
<p>Suppose you're building a web search engine. Two of your modules might be <code>getWebPage()</code>, which downloads web pages, and <code>extractWords()</code>, which splits a page into its component words:</p><pre><code class="language-java hljs"><span class="hljs-comment">/** <span class="hljs-doctag">@return</span> the contents of the web page downloaded from url
*/</span>
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> String <span class="hljs-title">getWebPage</span><span class="hljs-params">(URL url)</span> </span>{...}
<span class="hljs-comment">/** <span class="hljs-doctag">@return</span> the words in string s, in the order they appear,
where a word is a contiguous sequence of
non-whitespace and non-punctuation characters
*/</span>
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> List<String> <span class="hljs-title">extractWords</span><span class="hljs-params">(String s)</span> </span>{ ... }</code></pre>
<p>These methods might be used by another module <code>makeIndex()</code> as part of the web crawler that makes the search engine's index:</p><pre><code class="language-java hljs"><span class="hljs-comment">/** <span class="hljs-doctag">@return</span> an index mapping a word to the set of URLs
containing that word, for all webpages in the input set
*/</span>
<span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> Map<String, Set<URL>> makeIndex(Set<URL> urls) {
...
<span class="hljs-keyword">for</span> (URL url : urls) {
String page = getWebPage(url);
List<String> words = extractWords(page);
...
}
...
} </code></pre>
<p>In our test suite, we would want:</p>
<ul>
<li>unit tests just for <code>getWebPage()</code> that test it on various URLs</li>
<li>unit tests just for <code>extractWords()</code> that test it on various strings</li>
<li>unit tests for <code>makeIndex()</code> that test it on various sets of URLs</li>
</ul>
<p>One mistake that programmers sometimes make is writing test cases for <code>extractWords()</code> in such a way that the test cases depend on <code>getWebPage()</code> to be correct. It's better to think about and test <code>extractWords()</code> in isolation, and partition it. Using test partitions that involve web page content might be reasonable, because that's how <code>extractWords()</code> is actually used in the program. But don't actually call <code>getWebPage()</code> from the test case, because <code>getWebPage()</code> may be buggy! Instead, store web page content as a literal string, and pass it directly to <code>extractWords()</code>. That way you're writing an isolated unit test, and if it fails, you can be more confident that the bug is in the module it's actually testing, <code>extractWords()</code>.</p>
<p>Note that the unit tests for <code>makeIndex()</code> can't easily be isolated in this way. When a test case calls <code>makeIndex()</code>, it is testing the correctness of not only the code inside <code>makeIndex()</code>, but also all the methods called by <code>makeIndex()</code>. If the test fails, the bug might be in any of those methods. That's why we want separate tests for <code>getWebPage()</code> and <code>extractWords()</code>, to increase our confidence in those modules individually and localize the problem to the <code>makeIndex()</code> code that connects them together. </p>
<p>Isolating a higher-level module like <code>makeIndex()</code> is possible if we write <strong>stub</strong> versions of the modules that it calls. For example, a stub for <code>getWebPage()</code> wouldn't access the internet at all, but instead would return mock web page content no matter what URL was passed to it. A stub for a class is often called a <a href="http://en.wikipedia.org/wiki/Mock_object"><strong>mock object</strong></a>. Stubs are an important technique when building large systems, but we will generally not use them in 6.005.</p>
</div>
</div>
</div>
</div>
</div>
<div class="xblock xblock-public_view xblock-public_view-vertical" data-course-id="course-v1:MITx+6.005.1x+3T2016" data-graded="True" data-init="VerticalStudentView" data-request-token="9dc66f4a223711f0978c16ffcd2b1d4d" data-runtime-version="1" data-block-type="vertical" data-usage-id="block-v1:MITx+6.005.1x+3T2016+type@vertical+block@vertical_Questions_630d678baca9" data-runtime-class="LmsRuntime" data-has-score="False">
<h2 class="hd hd-2 unit-title">Questions</h2>
<div class="vert-mod">
<div class="vert vert-0" data-id="block-v1:MITx+6.005.1x+3T2016+type@html+block@html_fff67ba8819a">
<div class="xblock xblock-public_view xblock-public_view-html xmodule_display xmodule_HtmlBlock" data-course-id="course-v1:MITx+6.005.1x+3T2016" data-graded="True" data-init="XBlockToXModuleShim" data-request-token="9dc66f4a223711f0978c16ffcd2b1d4d" data-runtime-version="1" data-block-type="html" data-usage-id="block-v1:MITx+6.005.1x+3T2016+type@html+block@html_fff67ba8819a" data-runtime-class="LmsRuntime" data-has-score="False">
<script type="json/xblock-args" class="xblock-json-init-args">
{"xmodule-type": "HTMLModule"}
</script>
<link href="/assets/courseware/v1/9fab367942e94f98d32835b3ef4df11d/asset-v1:MITx+6.005.1x+3T2016+type@asset+block/prism-edx-v1.css" rel="stylesheet" type="text/css" />
<link href="/assets/courseware/v1/9fab367942e94f98d32835b3ef4df11d/asset-v1:MITx+6.005.1x+3T2016+type@asset+block/prism-edx-v1.css" rel="stylesheet" type="text/css" />
<script src="/assets/courseware/v1/3e6443fb95285d2dc06e8ffc448b9bdf/asset-v1:MITx+6.005.1x+3T2016+type@asset+block/prism.js"></script>
<script src="/assets/courseware/v1/2ba76f8bdfef4e2d45e31a3dc5208470/asset-v1:MITx+6.005.1x+3T2016+type@asset+block/edx-script-v1.js"></script>
</div>
</div>
<div class="vert vert-1" data-id="block-v1:MITx+6.005.1x+3T2016+type@problem+block@03-unit-testing">
<div class="xblock xblock-public_view xblock-public_view-problem xmodule_display xmodule_ProblemBlock" data-course-id="course-v1:MITx+6.005.1x+3T2016" data-graded="True" data-init="XBlockToXModuleShim" data-request-token="9dc66f4a223711f0978c16ffcd2b1d4d" data-runtime-version="1" data-block-type="problem" data-usage-id="block-v1:MITx+6.005.1x+3T2016+type@problem+block@03-unit-testing" data-runtime-class="LmsRuntime" data-has-score="True">
<script type="json/xblock-args" class="xblock-json-init-args">
{"xmodule-type": "Problem"}
</script>
<div id="problem_03-unit-testing" class="problems-wrapper" role="group"
aria-labelledby="03-unit-testing-problem-title"
data-problem-id="block-v1:MITx+6.005.1x+3T2016+type@problem+block@03-unit-testing" data-url="/courses/course-v1:MITx+6.005.1x+3T2016/xblock/block-v1:MITx+6.005.1x+3T2016+type@problem+block@03-unit-testing/handler/xmodule_handler"
data-problem-score="0"
data-problem-total-possible="3"
data-attempts-used="0"
data-content="
<h3 class="hd hd-3 problem-header" id="03-unit-testing-problem-title" aria-describedby="block-v1:MITx+6.005.1x+3T2016+type@problem+block@03-unit-testing-problem-progress" tabindex="-1">
unit testing
</h3>
<div class="problem-progress" id="block-v1:MITx+6.005.1x+3T2016+type@problem+block@03-unit-testing-problem-progress"></div>
<div class="problem">
<div>
<p>The <a href="http://en.wikipedia.org/wiki/RSA_%28cryptosystem%29">RSA cryptography algorithm</a> needs two prime numbers, p and q, to encrypt and decrypt messages. The encryption key is the product n=pq, and the decryption key is p and q.</p>
<p>Suppose you are building an RSA implementation with several modules in it:</p>
<pre class="code">
long randomPrimeNumber();
String encrypt(long n, String message);
String decrypt(long p, long q, String message);
</pre>
<p>Construct a suitable <b>unit test</b> for decrypt() below by choosing code to replace code1, code2, and code3. Assume the resulting test is correct.</p>
<pre class="code">
String originalMessage = "hello!";
code1
code2
code3
assertEquals(originalMessage, decryptedMessage);
</pre>
<p>code1</p>
<div class="wrapper-problem-response" tabindex="-1" aria-label="Question 1" role="group"><div class="choicegroup capa_inputtype" id="inputtype_03-unit-testing_2_1">
<fieldset aria-describedby="status_03-unit-testing_2_1">
<div class="field">
<input type="radio" name="input_03-unit-testing_2_1" id="input_03-unit-testing_2_1_choice_0" class="field-input input-radio" value="choice_0"/><label id="03-unit-testing_2_1-choice_0-label" for="input_03-unit-testing_2_1_choice_0" class="response-label field-label label-inline" aria-describedby="status_03-unit-testing_2_1"> long p = randomPrimeNumber(); long q = randomPrimeNumber();
</label>
</div>
<div class="field">
<input type="radio" name="input_03-unit-testing_2_1" id="input_03-unit-testing_2_1_choice_1" class="field-input input-radio" value="choice_1"/><label id="03-unit-testing_2_1-choice_1-label" for="input_03-unit-testing_2_1_choice_1" class="response-label field-label label-inline" aria-describedby="status_03-unit-testing_2_1"> long p = 17; long q = 37;
</label>
</div>
<span id="answer_03-unit-testing_2_1"/>
</fieldset>
<div class="indicator-container">
<span class="status unanswered" id="status_03-unit-testing_2_1" data-tooltip="Not yet answered.">
<span class="sr">unanswered</span><span class="status-icon" aria-hidden="true"/>
</span>
</div>
</div></div>
<p>code2</p>
<div class="wrapper-problem-response" tabindex="-1" aria-label="Question 2" role="group"><div class="choicegroup capa_inputtype" id="inputtype_03-unit-testing_3_1">
<fieldset aria-describedby="status_03-unit-testing_3_1">
<div class="field">
<input type="radio" name="input_03-unit-testing_3_1" id="input_03-unit-testing_3_1_choice_0" class="field-input input-radio" value="choice_0"/><label id="03-unit-testing_3_1-choice_0-label" for="input_03-unit-testing_3_1_choice_0" class="response-label field-label label-inline" aria-describedby="status_03-unit-testing_3_1"> String encryptedMessage = "iy@94RFe"
</label>
</div>
<div class="field">
<input type="radio" name="input_03-unit-testing_3_1" id="input_03-unit-testing_3_1_choice_1" class="field-input input-radio" value="choice_1"/><label id="03-unit-testing_3_1-choice_1-label" for="input_03-unit-testing_3_1_choice_1" class="response-label field-label label-inline" aria-describedby="status_03-unit-testing_3_1"> String encryptedMessage = encrypt(p*q, originalMessage);
</label>
</div>
<span id="answer_03-unit-testing_3_1"/>
</fieldset>
<div class="indicator-container">
<span class="status unanswered" id="status_03-unit-testing_3_1" data-tooltip="Not yet answered.">
<span class="sr">unanswered</span><span class="status-icon" aria-hidden="true"/>
</span>
</div>
</div></div>
<p>code3</p>
<div class="wrapper-problem-response" tabindex="-1" aria-label="Question 3" role="group"><div class="choicegroup capa_inputtype" id="inputtype_03-unit-testing_4_1">
<fieldset aria-describedby="status_03-unit-testing_4_1">
<div class="field">
<input type="radio" name="input_03-unit-testing_4_1" id="input_03-unit-testing_4_1_choice_0" class="field-input input-radio" value="choice_0"/><label id="03-unit-testing_4_1-choice_0-label" for="input_03-unit-testing_4_1_choice_0" class="response-label field-label label-inline" aria-describedby="status_03-unit-testing_4_1"> String decryptedMessage = decrypt(p, q, encryptedMessage);
</label>
</div>
<div class="field">
<input type="radio" name="input_03-unit-testing_4_1" id="input_03-unit-testing_4_1_choice_1" class="field-input input-radio" value="choice_1"/><label id="03-unit-testing_4_1-choice_1-label" for="input_03-unit-testing_4_1_choice_1" class="response-label field-label label-inline" aria-describedby="status_03-unit-testing_4_1"> String decryptedMessage = "hello!";
</label>
</div>
<span id="answer_03-unit-testing_4_1"/>
</fieldset>
<div class="indicator-container">
<span class="status unanswered" id="status_03-unit-testing_4_1" data-tooltip="Not yet answered.">
<span class="sr">unanswered</span><span class="status-icon" aria-hidden="true"/>
</span>
</div>
</div></div>
<div class="solution-span">
<span id="solution_03-unit-testing_solution_1"/>
</div></div>
<div class="action">
<input type="hidden" name="problem_id" value="unit testing" />
<div class="submit-attempt-container">
<button type="button" class="submit btn-brand" data-submitting="Submitting" data-value="Submit" data-should-enable-submit-button="True" aria-describedby="submission_feedback_03-unit-testing" >
<span class="submit-label">Submit</span>
</button>
<div class="submission-feedback" id="submission_feedback_03-unit-testing">
<span class="sr">Some problems have options such as save, reset, hints, or show answer. These options follow the Submit button.</span>
</div>
</div>
<div class="problem-action-buttons-wrapper">
</div>
</div>
<div class="notification warning notification-gentle-alert
is-hidden"
tabindex="-1">
<span class="icon fa fa-exclamation-circle" aria-hidden="true"></span>
<span class="notification-message" aria-describedby="03-unit-testing-problem-title">
</span>
<div class="notification-btn-wrapper">
<button type="button" class="btn btn-default btn-small notification-btn review-btn sr">Review</button>
</div>
</div>
<div class="notification warning notification-save
is-hidden"
tabindex="-1">
<span class="icon fa fa-save" aria-hidden="true"></span>
<span class="notification-message" aria-describedby="03-unit-testing-problem-title">None
</span>
<div class="notification-btn-wrapper">
<button type="button" class="btn btn-default btn-small notification-btn review-btn sr">Review</button>
</div>
</div>
<div class="notification general notification-show-answer
is-hidden"
tabindex="-1">
<span class="icon fa fa-info-circle" aria-hidden="true"></span>
<span class="notification-message" aria-describedby="03-unit-testing-problem-title">Answers are displayed within the problem
</span>
<div class="notification-btn-wrapper">
<button type="button" class="btn btn-default btn-small notification-btn review-btn sr">Review</button>
</div>
</div>
</div>
"
data-graded="True">
<p class="loading-spinner">
<i class="fa fa-spinner fa-pulse fa-2x fa-fw"></i>
<span class="sr">Loading…</span>
</p>
</div>
</div>
</div>
</div>
</div>
<div class="xblock xblock-public_view xblock-public_view-vertical" data-course-id="course-v1:MITx+6.005.1x+3T2016" data-graded="True" data-init="VerticalStudentView" data-request-token="9dc66f4a223711f0978c16ffcd2b1d4d" data-runtime-version="1" data-block-type="vertical" data-usage-id="block-v1:MITx+6.005.1x+3T2016+type@vertical+block@vertical-automated-testing-and-regression-testing" data-runtime-class="LmsRuntime" data-has-score="False">
<h2 class="hd hd-2 unit-title">Automated Testing and Regression Testing</h2>
<div class="vert-mod">
<div class="vert vert-0" data-id="block-v1:MITx+6.005.1x+3T2016+type@video+block@video_829ad55d749f">
<div class="xblock xblock-public_view xblock-public_view-video xmodule_display xmodule_VideoBlock" data-course-id="course-v1:MITx+6.005.1x+3T2016" data-graded="True" data-init="XBlockToXModuleShim" data-request-token="9dc66f4a223711f0978c16ffcd2b1d4d" data-runtime-version="1" data-block-type="video" data-usage-id="block-v1:MITx+6.005.1x+3T2016+type@video+block@video_829ad55d749f" data-runtime-class="LmsRuntime" data-has-score="False">
<script type="json/xblock-args" class="xblock-json-init-args">
{"xmodule-type": "Video"}
</script>
<h3 class="hd hd-2">Video</h3>
<div
id="video_video_829ad55d749f"
class="video closed"
data-metadata='{"publishCompletionUrl": "/courses/course-v1:MITx+6.005.1x+3T2016/xblock/block-v1:MITx+6.005.1x+3T2016+type@video+block@video_829ad55d749f/handler/publish_completion", "duration": 246.69, "transcriptLanguage": "en", "ytTestTimeout": 1500, "prioritizeHls": false, "generalSpeed": 1.0, "sources": ["https://d2f1egay8yehza.cloudfront.net/MIT600512016-V002300_DTH.mp4", "https://d2f1egay8yehza.cloudfront.net/MIT600512016-V002300/MIT600512016-V002300.m3u8"], "captionDataDir": null, "autoAdvance": false, "poster": null, "autohideHtml5": false, "speed": null, "transcriptTranslationUrl": "/courses/course-v1:MITx+6.005.1x+3T2016/xblock/block-v1:MITx+6.005.1x+3T2016+type@video+block@video_829ad55d749f/handler/transcript/translation/__lang__", "recordedYoutubeIsAvailable": true, "completionEnabled": false, "end": 0.0, "ytMetadataEndpoint": "", "completionPercentage": 0.95, "savedVideoPosition": 0.0, "lmsRootURL": "https://openlearninglibrary.mit.edu", "saveStateEnabled": false, "start": 0.0, "streams": "1.00:bD58IoKhXMI", "transcriptAvailableTranslationsUrl": "/courses/course-v1:MITx+6.005.1x+3T2016/xblock/block-v1:MITx+6.005.1x+3T2016+type@video+block@video_829ad55d749f/handler/transcript/available_translations", "autoplay": false, "showCaptions": "true", "transcriptLanguages": {"en": "English"}, "saveStateUrl": "/courses/course-v1:MITx+6.005.1x+3T2016/xblock/block-v1:MITx+6.005.1x+3T2016+type@video+block@video_829ad55d749f/handler/xmodule_handler/save_user_state", "ytApiUrl": "https://www.youtube.com/iframe_api"}'
data-bumper-metadata='null'
data-autoadvance-enabled="False"
data-poster='null'
tabindex="-1"
>
<div class="focus_grabber first"></div>
<div class="tc-wrapper">
<div class="video-wrapper">
<span tabindex="0" class="spinner" aria-hidden="false" aria-label="Loading video player"></span>
<span tabindex="-1" class="btn-play fa fa-youtube-play fa-2x is-hidden" aria-hidden="true" aria-label="Play video"></span>
<div class="video-player-pre"></div>
<div class="video-player">
<div id="video_829ad55d749f"></div>
<h4 class="hd hd-4 video-error is-hidden">No playable video sources found.</h4>
<h4 class="hd hd-4 video-hls-error is-hidden">
Your browser does not support this video format. Try using a different browser.
</h4>
</div>
<div class="video-player-post"></div>
<div class="closed-captions"></div>
<div class="video-controls is-hidden">
<div>
<div class="vcr"><div class="vidtime">0:00 / 0:00</div></div>
<div class="secondary-controls"></div>
</div>
</div>
</div>
</div>
<div class="focus_grabber last"></div>
<h3 class="hd hd-4 downloads-heading sr" id="video-download-transcripts_video_829ad55d749f">Downloads and transcripts</h3>
<div class="wrapper-downloads" role="region" aria-labelledby="video-download-transcripts_video_829ad55d749f">
<div class="wrapper-download-transcripts">
<h4 class="hd hd-5">Transcripts</h4>
<ul class="list-download-transcripts">
<li class="transcript-option">
<a class="btn btn-link" href="/courses/course-v1:MITx+6.005.1x+3T2016/xblock/block-v1:MITx+6.005.1x+3T2016+type@video+block@video_829ad55d749f/handler/transcript/download" data-value="srt">Download SubRip (.srt) file</a>
</li>
<li class="transcript-option">
<a class="btn btn-link" href="/courses/course-v1:MITx+6.005.1x+3T2016/xblock/block-v1:MITx+6.005.1x+3T2016+type@video+block@video_829ad55d749f/handler/transcript/download" data-value="txt">Download Text (.txt) file</a>
</li>
</ul>
</div>
</div>
</div>
</div>
</div>
<div class="vert vert-1" data-id="block-v1:MITx+6.005.1x+3T2016+type@html+block@html_3349bcdf1a92">
<div class="xblock xblock-public_view xblock-public_view-html xmodule_display xmodule_HtmlBlock" data-course-id="course-v1:MITx+6.005.1x+3T2016" data-graded="True" data-init="XBlockToXModuleShim" data-request-token="9dc66f4a223711f0978c16ffcd2b1d4d" data-runtime-version="1" data-block-type="html" data-usage-id="block-v1:MITx+6.005.1x+3T2016+type@html+block@html_3349bcdf1a92" data-runtime-class="LmsRuntime" data-has-score="False">
<script type="json/xblock-args" class="xblock-json-init-args">
{"xmodule-type": "HTMLModule"}
</script>
<link href="/assets/courseware/v1/9fab367942e94f98d32835b3ef4df11d/asset-v1:MITx+6.005.1x+3T2016+type@asset+block/prism-edx-v1.css" rel="stylesheet" type="text/css" />
<h2 id="automated_testing_and_regression_testing">Automated Testing and Regression Testing</h2>
<div data-outline="automated_testing_and_regression_testing">
<p>Nothing makes tests easier to run, and more likely to be run, than complete automation.
<strong>Automated testing</strong> means running the tests and checking their results automatically. A test driver should not be an interactive program that prompts you for inputs and prints out results for you to manually check. Instead, a test driver should invoke the module itself on fixed test cases and automatically check that the results are correct. The result of the test driver should be either “all tests OK” or “these tests failed: …” A good testing framework, like JUnit, helps you build automated test suites.</p>
<p>Note that automated testing frameworks like JUnit make it easy to run the tests, but you still have to come up with good test cases yourself.
<em>Automatic test generation</em> is a hard problem, still a subject of active computer science research.</p>
<p>Once you have test automation, it's very important to rerun your tests when you modify your code. This prevents your program from <em>regressing</em> — introducing other bugs when you fix new bugs or add new features. Running all your tests after every change is called <strong>regression testing</strong>.</p>
<p>Whenever you find and fix a bug, take the input that elicited the bug and add it to your automated test suite as a test case. This kind of test case is called a <em>regression test</em>. This helps to populate your test suite with good test cases. Remember that a test is good if it elicits a bug — and every regression test did find a bug in one version of your code! Saving regression tests also protects against reversions that reintroduce the bug. The bug may be an easy error to make, since it happened once already.</p>
<p>This idea also leads to <em>test-first debugging</em>. When a bug arises, immediately write a test case for it that elicits it, and immediately add it to your test suite. Once you find and fix the bug, all your test cases will be passing, and you'll be done with debugging and have a regression test for that bug.</p>
<p>In practice, these two ideas, automated testing and regression testing, are almost always used in combination.
<br> Regression testing is only practical if the tests can be run often, automatically. Conversely, if you already have automated testing in place for your project, then you might as well use it to prevent regressions. So <strong>automated regression testing</strong> is a best-practice of modern software engineering.</p>
</div>
</div>
</div>
</div>
</div>
<div class="xblock xblock-public_view xblock-public_view-vertical" data-course-id="course-v1:MITx+6.005.1x+3T2016" data-graded="True" data-init="VerticalStudentView" data-request-token="9dc66f4a223711f0978c16ffcd2b1d4d" data-runtime-version="1" data-block-type="vertical" data-usage-id="block-v1:MITx+6.005.1x+3T2016+type@vertical+block@vertical_Questions_131e2ee5c169" data-runtime-class="LmsRuntime" data-has-score="False">
<h2 class="hd hd-2 unit-title">Questions</h2>
<div class="vert-mod">
<div class="vert vert-0" data-id="block-v1:MITx+6.005.1x+3T2016+type@html+block@html_fff67ba8819a">
<div class="xblock xblock-public_view xblock-public_view-html xmodule_display xmodule_HtmlBlock" data-course-id="course-v1:MITx+6.005.1x+3T2016" data-graded="True" data-init="XBlockToXModuleShim" data-request-token="9dc66f4a223711f0978c16ffcd2b1d4d" data-runtime-version="1" data-block-type="html" data-usage-id="block-v1:MITx+6.005.1x+3T2016+type@html+block@html_fff67ba8819a" data-runtime-class="LmsRuntime" data-has-score="False">
<script type="json/xblock-args" class="xblock-json-init-args">
{"xmodule-type": "HTMLModule"}
</script>
<link href="/assets/courseware/v1/9fab367942e94f98d32835b3ef4df11d/asset-v1:MITx+6.005.1x+3T2016+type@asset+block/prism-edx-v1.css" rel="stylesheet" type="text/css" />
<link href="/assets/courseware/v1/9fab367942e94f98d32835b3ef4df11d/asset-v1:MITx+6.005.1x+3T2016+type@asset+block/prism-edx-v1.css" rel="stylesheet" type="text/css" />
<script src="/assets/courseware/v1/3e6443fb95285d2dc06e8ffc448b9bdf/asset-v1:MITx+6.005.1x+3T2016+type@asset+block/prism.js"></script>
<script src="/assets/courseware/v1/2ba76f8bdfef4e2d45e31a3dc5208470/asset-v1:MITx+6.005.1x+3T2016+type@asset+block/edx-script-v1.js"></script>
</div>
</div>
<div class="vert vert-1" data-id="block-v1:MITx+6.005.1x+3T2016+type@problem+block@03-regression-testing">
<div class="xblock xblock-public_view xblock-public_view-problem xmodule_display xmodule_ProblemBlock" data-course-id="course-v1:MITx+6.005.1x+3T2016" data-graded="True" data-init="XBlockToXModuleShim" data-request-token="9dc66f4a223711f0978c16ffcd2b1d4d" data-runtime-version="1" data-block-type="problem" data-usage-id="block-v1:MITx+6.005.1x+3T2016+type@problem+block@03-regression-testing" data-runtime-class="LmsRuntime" data-has-score="True">
<script type="json/xblock-args" class="xblock-json-init-args">
{"xmodule-type": "Problem"}
</script>
<div id="problem_03-regression-testing" class="problems-wrapper" role="group"
aria-labelledby="03-regression-testing-problem-title"
data-problem-id="block-v1:MITx+6.005.1x+3T2016+type@problem+block@03-regression-testing" data-url="/courses/course-v1:MITx+6.005.1x+3T2016/xblock/block-v1:MITx+6.005.1x+3T2016+type@problem+block@03-regression-testing/handler/xmodule_handler"
data-problem-score="0"
data-problem-total-possible="1"
data-attempts-used="0"
data-content="
<h3 class="hd hd-3 problem-header" id="03-regression-testing-problem-title" aria-describedby="block-v1:MITx+6.005.1x+3T2016+type@problem+block@03-regression-testing-problem-progress" tabindex="-1">
regression testing
</h3>
<div class="problem-progress" id="block-v1:MITx+6.005.1x+3T2016+type@problem+block@03-regression-testing-problem-progress"></div>
<div class="problem">
<div>
<div class="wrapper-problem-response" tabindex="-1" aria-label="Question 1" role="group"><div class="choicegroup capa_inputtype" id="inputtype_03-regression-testing_2_1">
<fieldset aria-describedby="status_03-regression-testing_2_1">
<legend id="03-regression-testing_2_1-legend" class="response-fieldset-legend field-group-hd">Which of the following best defines regression testing?</legend>
<div class="field">
<input type="radio" name="input_03-regression-testing_2_1" id="input_03-regression-testing_2_1_choice_0" class="field-input input-radio" value="choice_0"/><label id="03-regression-testing_2_1-choice_0-label" for="input_03-regression-testing_2_1_choice_0" class="response-label field-label label-inline" aria-describedby="status_03-regression-testing_2_1"> Changes should be tested against all inputs that elicited bugs in earlier versions of the code.
</label>
</div>
<div class="field">
<input type="radio" name="input_03-regression-testing_2_1" id="input_03-regression-testing_2_1_choice_1" class="field-input input-radio" value="choice_1"/><label id="03-regression-testing_2_1-choice_1-label" for="input_03-regression-testing_2_1_choice_1" class="response-label field-label label-inline" aria-describedby="status_03-regression-testing_2_1"> Every component in your code should have an associated set of tests that exercises all the corner cases in its specification.
</label>
</div>
<div class="field">
<input type="radio" name="input_03-regression-testing_2_1" id="input_03-regression-testing_2_1_choice_2" class="field-input input-radio" value="choice_2"/><label id="03-regression-testing_2_1-choice_2-label" for="input_03-regression-testing_2_1_choice_2" class="response-label field-label label-inline" aria-describedby="status_03-regression-testing_2_1"> Tests should be written before you write the code as a way of checking your understanding of the specification.
</label>
</div>
<div class="field">
<input type="radio" name="input_03-regression-testing_2_1" id="input_03-regression-testing_2_1_choice_3" class="field-input input-radio" value="choice_3"/><label id="03-regression-testing_2_1-choice_3-label" for="input_03-regression-testing_2_1_choice_3" class="response-label field-label label-inline" aria-describedby="status_03-regression-testing_2_1"> When a new test exposes a bug, you should run it on all previous versions of the code until you find the version where the bug was introduced.
</label>
</div>
<span id="answer_03-regression-testing_2_1"/>
</fieldset>
<div class="indicator-container">
<span class="status unanswered" id="status_03-regression-testing_2_1" data-tooltip="Not yet answered.">
<span class="sr">unanswered</span><span class="status-icon" aria-hidden="true"/>
</span>
</div>
</div></div>
<div class="solution-span">
<span id="solution_03-regression-testing_solution_1"/>
</div></div>
<div class="action">
<input type="hidden" name="problem_id" value="regression testing" />
<div class="submit-attempt-container">
<button type="button" class="submit btn-brand" data-submitting="Submitting" data-value="Submit" data-should-enable-submit-button="True" aria-describedby="submission_feedback_03-regression-testing" >
<span class="submit-label">Submit</span>
</button>
<div class="submission-feedback" id="submission_feedback_03-regression-testing">
<span class="sr">Some problems have options such as save, reset, hints, or show answer. These options follow the Submit button.</span>
</div>
</div>
<div class="problem-action-buttons-wrapper">
</div>
</div>
<div class="notification warning notification-gentle-alert
is-hidden"
tabindex="-1">
<span class="icon fa fa-exclamation-circle" aria-hidden="true"></span>
<span class="notification-message" aria-describedby="03-regression-testing-problem-title">
</span>
<div class="notification-btn-wrapper">
<button type="button" class="btn btn-default btn-small notification-btn review-btn sr">Review</button>
</div>
</div>
<div class="notification warning notification-save
is-hidden"
tabindex="-1">
<span class="icon fa fa-save" aria-hidden="true"></span>
<span class="notification-message" aria-describedby="03-regression-testing-problem-title">None
</span>
<div class="notification-btn-wrapper">
<button type="button" class="btn btn-default btn-small notification-btn review-btn sr">Review</button>
</div>
</div>
<div class="notification general notification-show-answer
is-hidden"
tabindex="-1">
<span class="icon fa fa-info-circle" aria-hidden="true"></span>
<span class="notification-message" aria-describedby="03-regression-testing-problem-title">Answers are displayed within the problem
</span>
<div class="notification-btn-wrapper">
<button type="button" class="btn btn-default btn-small notification-btn review-btn sr">Review</button>
</div>
</div>
</div>
"
data-graded="True">
<p class="loading-spinner">
<i class="fa fa-spinner fa-pulse fa-2x fa-fw"></i>
<span class="sr">Loading…</span>
</p>
</div>
</div>
</div>
<div class="vert vert-2" data-id="block-v1:MITx+6.005.1x+3T2016+type@problem+block@03-running-automated-tests">
<div class="xblock xblock-public_view xblock-public_view-problem xmodule_display xmodule_ProblemBlock" data-course-id="course-v1:MITx+6.005.1x+3T2016" data-graded="True" data-init="XBlockToXModuleShim" data-request-token="9dc66f4a223711f0978c16ffcd2b1d4d" data-runtime-version="1" data-block-type="problem" data-usage-id="block-v1:MITx+6.005.1x+3T2016+type@problem+block@03-running-automated-tests" data-runtime-class="LmsRuntime" data-has-score="True">
<script type="json/xblock-args" class="xblock-json-init-args">
{"xmodule-type": "Problem"}
</script>
<div id="problem_03-running-automated-tests" class="problems-wrapper" role="group"
aria-labelledby="03-running-automated-tests-problem-title"
data-problem-id="block-v1:MITx+6.005.1x+3T2016+type@problem+block@03-running-automated-tests" data-url="/courses/course-v1:MITx+6.005.1x+3T2016/xblock/block-v1:MITx+6.005.1x+3T2016+type@problem+block@03-running-automated-tests/handler/xmodule_handler"
data-problem-score="0"
data-problem-total-possible="1"
data-attempts-used="0"
data-content="
<h3 class="hd hd-3 problem-header" id="03-running-automated-tests-problem-title" aria-describedby="block-v1:MITx+6.005.1x+3T2016+type@problem+block@03-running-automated-tests-problem-progress" tabindex="-1">
running automated tests
</h3>
<div class="problem-progress" id="block-v1:MITx+6.005.1x+3T2016+type@problem+block@03-running-automated-tests-problem-progress"></div>
<div class="problem">
<div>
<p>Which of the following are good times to rerun all your JUnit tests? Check all that apply.</p>
<div class="wrapper-problem-response" tabindex="-1" aria-label="Question 1" role="group"><div class="choicegroup capa_inputtype" id="inputtype_03-running-automated-tests_2_1">
<fieldset aria-describedby="status_03-running-automated-tests_2_1">
<div class="field">
<input type="checkbox" name="input_03-running-automated-tests_2_1[]" id="input_03-running-automated-tests_2_1_choice_0" class="field-input input-checkbox" value="choice_0"/><label id="03-running-automated-tests_2_1-choice_0-label" for="input_03-running-automated-tests_2_1_choice_0" class="response-label field-label label-inline" aria-describedby="status_03-running-automated-tests_2_1"> Before doing git add/commit/push
</label>
</div>
<div class="field">
<input type="checkbox" name="input_03-running-automated-tests_2_1[]" id="input_03-running-automated-tests_2_1_choice_1" class="field-input input-checkbox" value="choice_1"/><label id="03-running-automated-tests_2_1-choice_1-label" for="input_03-running-automated-tests_2_1_choice_1" class="response-label field-label label-inline" aria-describedby="status_03-running-automated-tests_2_1"> After rewriting a function to make it faster
</label>
</div>
<div class="field">
<input type="checkbox" name="input_03-running-automated-tests_2_1[]" id="input_03-running-automated-tests_2_1_choice_2" class="field-input input-checkbox" value="choice_2"/><label id="03-running-automated-tests_2_1-choice_2-label" for="input_03-running-automated-tests_2_1_choice_2" class="response-label field-label label-inline" aria-describedby="status_03-running-automated-tests_2_1"> When using a code coverage tool
</label>
</div>
<div class="field">
<input type="checkbox" name="input_03-running-automated-tests_2_1[]" id="input_03-running-automated-tests_2_1_choice_3" class="field-input input-checkbox" value="choice_3"/><label id="03-running-automated-tests_2_1-choice_3-label" for="input_03-running-automated-tests_2_1_choice_3" class="response-label field-label label-inline" aria-describedby="status_03-running-automated-tests_2_1"> After you think you fixed a bug
</label>
</div>
<span id="answer_03-running-automated-tests_2_1"/>
</fieldset>
<div class="indicator-container">
<span class="status unanswered" id="status_03-running-automated-tests_2_1" data-tooltip="Not yet answered.">
<span class="sr">unanswered</span><span class="status-icon" aria-hidden="true"/>
</span>
</div>
</div></div>
<div class="solution-span">
<span id="solution_03-running-automated-tests_solution_1"/>
</div></div>
<div class="action">
<input type="hidden" name="problem_id" value="running automated tests" />
<div class="submit-attempt-container">
<button type="button" class="submit btn-brand" data-submitting="Submitting" data-value="Submit" data-should-enable-submit-button="True" aria-describedby="submission_feedback_03-running-automated-tests" >
<span class="submit-label">Submit</span>
</button>
<div class="submission-feedback" id="submission_feedback_03-running-automated-tests">
<span class="sr">Some problems have options such as save, reset, hints, or show answer. These options follow the Submit button.</span>
</div>
</div>
<div class="problem-action-buttons-wrapper">
</div>
</div>
<div class="notification warning notification-gentle-alert
is-hidden"
tabindex="-1">
<span class="icon fa fa-exclamation-circle" aria-hidden="true"></span>
<span class="notification-message" aria-describedby="03-running-automated-tests-problem-title">
</span>
<div class="notification-btn-wrapper">
<button type="button" class="btn btn-default btn-small notification-btn review-btn sr">Review</button>
</div>
</div>
<div class="notification warning notification-save
is-hidden"
tabindex="-1">
<span class="icon fa fa-save" aria-hidden="true"></span>
<span class="notification-message" aria-describedby="03-running-automated-tests-problem-title">None
</span>
<div class="notification-btn-wrapper">
<button type="button" class="btn btn-default btn-small notification-btn review-btn sr">Review</button>
</div>
</div>
<div class="notification general notification-show-answer
is-hidden"
tabindex="-1">
<span class="icon fa fa-info-circle" aria-hidden="true"></span>
<span class="notification-message" aria-describedby="03-running-automated-tests-problem-title">Answers are displayed within the problem
</span>
<div class="notification-btn-wrapper">
<button type="button" class="btn btn-default btn-small notification-btn review-btn sr">Review</button>
</div>
</div>
</div>
"
data-graded="True">
<p class="loading-spinner">
<i class="fa fa-spinner fa-pulse fa-2x fa-fw"></i>
<span class="sr">Loading…</span>
</p>
</div>
</div>
</div>
<div class="vert vert-3" data-id="block-v1:MITx+6.005.1x+3T2016+type@problem+block@03-testing-techniques">
<div class="xblock xblock-public_view xblock-public_view-problem xmodule_display xmodule_ProblemBlock" data-course-id="course-v1:MITx+6.005.1x+3T2016" data-graded="True" data-init="XBlockToXModuleShim" data-request-token="9dc66f4a223711f0978c16ffcd2b1d4d" data-runtime-version="1" data-block-type="problem" data-usage-id="block-v1:MITx+6.005.1x+3T2016+type@problem+block@03-testing-techniques" data-runtime-class="LmsRuntime" data-has-score="True">
<script type="json/xblock-args" class="xblock-json-init-args">
{"xmodule-type": "Problem"}
</script>
<div id="problem_03-testing-techniques" class="problems-wrapper" role="group"
aria-labelledby="03-testing-techniques-problem-title"
data-problem-id="block-v1:MITx+6.005.1x+3T2016+type@problem+block@03-testing-techniques" data-url="/courses/course-v1:MITx+6.005.1x+3T2016/xblock/block-v1:MITx+6.005.1x+3T2016+type@problem+block@03-testing-techniques/handler/xmodule_handler"
data-problem-score="0"
data-problem-total-possible="1"
data-attempts-used="0"
data-content="
<h3 class="hd hd-3 problem-header" id="03-testing-techniques-problem-title" aria-describedby="block-v1:MITx+6.005.1x+3T2016+type@problem+block@03-testing-techniques-problem-progress" tabindex="-1">
testing techniques
</h3>
<div class="problem-progress" id="block-v1:MITx+6.005.1x+3T2016+type@problem+block@03-testing-techniques-problem-progress"></div>
<div class="problem">
<div>
<p>Which of these techniques are useful for choosing test cases in test-first programming, before any code is written? Check all that apply.</p>
<div class="wrapper-problem-response" tabindex="-1" aria-label="Question 1" role="group"><div class="choicegroup capa_inputtype" id="inputtype_03-testing-techniques_2_1">
<fieldset aria-describedby="status_03-testing-techniques_2_1">
<div class="field">
<input type="checkbox" name="input_03-testing-techniques_2_1[]" id="input_03-testing-techniques_2_1_choice_0" class="field-input input-checkbox" value="choice_0"/><label id="03-testing-techniques_2_1-choice_0-label" for="input_03-testing-techniques_2_1_choice_0" class="response-label field-label label-inline" aria-describedby="status_03-testing-techniques_2_1"> black box
</label>
</div>
<div class="field">
<input type="checkbox" name="input_03-testing-techniques_2_1[]" id="input_03-testing-techniques_2_1_choice_1" class="field-input input-checkbox" value="choice_1"/><label id="03-testing-techniques_2_1-choice_1-label" for="input_03-testing-techniques_2_1_choice_1" class="response-label field-label label-inline" aria-describedby="status_03-testing-techniques_2_1"> regression
</label>
</div>
<div class="field">
<input type="checkbox" name="input_03-testing-techniques_2_1[]" id="input_03-testing-techniques_2_1_choice_2" class="field-input input-checkbox" value="choice_2"/><label id="03-testing-techniques_2_1-choice_2-label" for="input_03-testing-techniques_2_1_choice_2" class="response-label field-label label-inline" aria-describedby="status_03-testing-techniques_2_1"> static typing
</label>
</div>
<div class="field">
<input type="checkbox" name="input_03-testing-techniques_2_1[]" id="input_03-testing-techniques_2_1_choice_3" class="field-input input-checkbox" value="choice_3"/><label id="03-testing-techniques_2_1-choice_3-label" for="input_03-testing-techniques_2_1_choice_3" class="response-label field-label label-inline" aria-describedby="status_03-testing-techniques_2_1"> partitioning
</label>
</div>
<div class="field">
<input type="checkbox" name="input_03-testing-techniques_2_1[]" id="input_03-testing-techniques_2_1_choice_4" class="field-input input-checkbox" value="choice_4"/><label id="03-testing-techniques_2_1-choice_4-label" for="input_03-testing-techniques_2_1_choice_4" class="response-label field-label label-inline" aria-describedby="status_03-testing-techniques_2_1"> boundaries
</label>
</div>
<div class="field">
<input type="checkbox" name="input_03-testing-techniques_2_1[]" id="input_03-testing-techniques_2_1_choice_5" class="field-input input-checkbox" value="choice_5"/><label id="03-testing-techniques_2_1-choice_5-label" for="input_03-testing-techniques_2_1_choice_5" class="response-label field-label label-inline" aria-describedby="status_03-testing-techniques_2_1"> white box
</label>
</div>
<div class="field">
<input type="checkbox" name="input_03-testing-techniques_2_1[]" id="input_03-testing-techniques_2_1_choice_6" class="field-input input-checkbox" value="choice_6"/><label id="03-testing-techniques_2_1-choice_6-label" for="input_03-testing-techniques_2_1_choice_6" class="response-label field-label label-inline" aria-describedby="status_03-testing-techniques_2_1"> coverage
</label>
</div>
<span id="answer_03-testing-techniques_2_1"/>
</fieldset>
<div class="indicator-container">
<span class="status unanswered" id="status_03-testing-techniques_2_1" data-tooltip="Not yet answered.">
<span class="sr">unanswered</span><span class="status-icon" aria-hidden="true"/>
</span>
</div>
</div></div>
<div class="solution-span">
<span id="solution_03-testing-techniques_solution_1"/>
</div></div>
<div class="action">
<input type="hidden" name="problem_id" value="testing techniques" />
<div class="submit-attempt-container">
<button type="button" class="submit btn-brand" data-submitting="Submitting" data-value="Submit" data-should-enable-submit-button="True" aria-describedby="submission_feedback_03-testing-techniques" >
<span class="submit-label">Submit</span>
</button>
<div class="submission-feedback" id="submission_feedback_03-testing-techniques">
<span class="sr">Some problems have options such as save, reset, hints, or show answer. These options follow the Submit button.</span>
</div>
</div>
<div class="problem-action-buttons-wrapper">
</div>
</div>
<div class="notification warning notification-gentle-alert
is-hidden"
tabindex="-1">
<span class="icon fa fa-exclamation-circle" aria-hidden="true"></span>
<span class="notification-message" aria-describedby="03-testing-techniques-problem-title">
</span>
<div class="notification-btn-wrapper">
<button type="button" class="btn btn-default btn-small notification-btn review-btn sr">Review</button>
</div>
</div>
<div class="notification warning notification-save
is-hidden"
tabindex="-1">
<span class="icon fa fa-save" aria-hidden="true"></span>
<span class="notification-message" aria-describedby="03-testing-techniques-problem-title">None
</span>
<div class="notification-btn-wrapper">
<button type="button" class="btn btn-default btn-small notification-btn review-btn sr">Review</button>
</div>
</div>
<div class="notification general notification-show-answer
is-hidden"
tabindex="-1">
<span class="icon fa fa-info-circle" aria-hidden="true"></span>
<span class="notification-message" aria-describedby="03-testing-techniques-problem-title">Answers are displayed within the problem
</span>
<div class="notification-btn-wrapper">
<button type="button" class="btn btn-default btn-small notification-btn review-btn sr">Review</button>
</div>
</div>
</div>
"
data-graded="True">
<p class="loading-spinner">
<i class="fa fa-spinner fa-pulse fa-2x fa-fw"></i>
<span class="sr">Loading…</span>
</p>
</div>
</div>
</div>
</div>
</div>
<div class="xblock xblock-public_view xblock-public_view-vertical" data-course-id="course-v1:MITx+6.005.1x+3T2016" data-graded="True" data-init="VerticalStudentView" data-request-token="9dc66f4a223711f0978c16ffcd2b1d4d" data-runtime-version="1" data-block-type="vertical" data-usage-id="block-v1:MITx+6.005.1x+3T2016+type@vertical+block@Reading_3_Summary" data-runtime-class="LmsRuntime" data-has-score="False">
<h2 class="hd hd-2 unit-title">Reading 3 Summary</h2>
<div class="vert-mod">
<div class="vert vert-0" data-id="block-v1:MITx+6.005.1x+3T2016+type@html+block@html_3640d881cbef">
<div class="xblock xblock-public_view xblock-public_view-html xmodule_display xmodule_HtmlBlock" data-course-id="course-v1:MITx+6.005.1x+3T2016" data-graded="True" data-init="XBlockToXModuleShim" data-request-token="9dc66f4a223711f0978c16ffcd2b1d4d" data-runtime-version="1" data-block-type="html" data-usage-id="block-v1:MITx+6.005.1x+3T2016+type@html+block@html_3640d881cbef" data-runtime-class="LmsRuntime" data-has-score="False">
<script type="json/xblock-args" class="xblock-json-init-args">
{"xmodule-type": "HTMLModule"}
</script>
<link href="/assets/courseware/v1/9fab367942e94f98d32835b3ef4df11d/asset-v1:MITx+6.005.1x+3T2016+type@asset+block/prism-edx-v1.css" rel="stylesheet" type="text/css" />
<h2 id="summary">Summary</h2>
<div data-outline="summary">
<p>In this reading, we saw these ideas:</p>
<ul>
<li>Test-first programming. Write tests before you write code.</li>
<li>Partitioning and boundaries for choosing test cases systematically.</li>
<li>White box testing and statement coverage for filling out a test suite.</li>
<li>Unit-testing each module in isolation as much as possible.</li>
<li>Automated regression testing to keep bugs from coming back.</li>
</ul>
<p>The topics of today's reading connect to our three key properties of good software as follows:</p>
<ul>
<li>
<p><strong>Safe from bugs.</strong> Testing is about finding bugs in your code and test-first programming is about finding them as early as possible, immediately after you introduced them.</p>
</li>
<li>
<p><strong>Easy to understand.</strong> Testing doesn't help with this as much as code review does.</p>
</li>
<li>
<p><strong>Ready for change.</strong> Readiness for change was considered by writing tests that only depend on behavior in the spec. We also talked about automated regression testing, which helps keep bugs from coming back when changes are made to code.</p>
</li>
</ul>
<hr>
</div>
<div class="license">This reading was collaboratively authored with contributions from: Saman Amarasinghe, Adam Chlipala, Srini Devadas, Michael Ernst, Max Goldman, John Guttag, Daniel Jackson, Rob Miller, Martin Rinard, and Armando Solar-Lezama. This work is licensed under <a rel="license" href="http://creativecommons.org/licenses/by-sa/4.0/">CC BY-SA 4.0</a>.</div>
</div>
</div>
</div>
</div>