<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://teaching.healthtech.dtu.dk:443/22118/index.php?action=history&amp;feed=atom&amp;title=Beginning_unit_test</id>
	<title>Beginning unit test - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://teaching.healthtech.dtu.dk:443/22118/index.php?action=history&amp;feed=atom&amp;title=Beginning_unit_test"/>
	<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk:443/22118/index.php?title=Beginning_unit_test&amp;action=history"/>
	<updated>2026-04-07T19:48:02Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.41.0</generator>
	<entry>
		<id>https://teaching.healthtech.dtu.dk:443/22118/index.php?title=Beginning_unit_test&amp;diff=216&amp;oldid=prev</id>
		<title>WikiSysop: /* Required course material for the lesson */</title>
		<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk:443/22118/index.php?title=Beginning_unit_test&amp;diff=216&amp;oldid=prev"/>
		<updated>2026-03-06T14:16:26Z</updated>

		<summary type="html">&lt;p&gt;&lt;span dir=&quot;auto&quot;&gt;&lt;span class=&quot;autocomment&quot;&gt;Required course material for the lesson&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 16:16, 6 March 2026&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l9&quot;&gt;Line 9:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 9:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Resource: [[Example code - Unit test]]&amp;lt;br&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Resource: [[Example code - Unit test]]&amp;lt;br&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Resource: [[Unit test - start of reverse polish notation class]]&amp;lt;br&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Resource: [[Unit test - start of reverse polish notation class]]&amp;lt;br&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;Blog: [https://www.joelonsoftware.com/2000/04/30/top-five-wrong-reasons-you-dont-have-testers/ On testing], by the founder of StackExchange.&amp;lt;br&amp;gt;&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-added&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;== Subjects covered ==&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;== Subjects covered ==&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id>https://teaching.healthtech.dtu.dk:443/22118/index.php?title=Beginning_unit_test&amp;diff=207&amp;oldid=prev</id>
		<title>WikiSysop: /* Exercises to be handed in */</title>
		<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk:443/22118/index.php?title=Beginning_unit_test&amp;diff=207&amp;oldid=prev"/>
		<updated>2026-03-06T12:50:49Z</updated>

		<summary type="html">&lt;p&gt;&lt;span dir=&quot;auto&quot;&gt;&lt;span class=&quot;autocomment&quot;&gt;Exercises to be handed in&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 14:50, 6 March 2026&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l17&quot;&gt;Line 17:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 17:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;== Exercises to be handed in ==&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;== Exercises to be handed in ==&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;You should make a special folder for the exercises. I will refer to my special folder as &amp;#039;&amp;#039;unittest&amp;#039;&amp;#039; in these exercises. You will also see some &amp;#039;&amp;#039;__pycache__&amp;#039;&amp;#039; folders appear in places. This is Pythons cache for &amp;quot;compiled&amp;quot; programs. It is safe to ignore and also to delete, because it may become outdated.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;You should make a special folder for the exercises. I will refer to my special folder as &amp;#039;&amp;#039;unittest&amp;#039;&amp;#039; in these exercises. You will also see some &amp;#039;&amp;#039;__pycache__&amp;#039;&amp;#039; folders appear in places. This is Pythons cache for &amp;quot;compiled&amp;quot; programs. It is safe to ignore and also to delete, because it may become outdated.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# Use your factorial function from exercise 2 in [[Making Functions]]. If you did not do so already, change it to use exceptions instead of &#039;&#039;&#039;sys.exit()&#039;&#039;&#039;, when an error occurs. Now make simple unit tests for the following test cases: 12, 2, 1, 0, -1, 3.0, 3.4, &quot;3&quot;, &quot;3.1.&quot;, &quot;ABC&quot;. The factorial function and all test functions must be in one single file (&#039;&#039;factorial_test.py&#039;&#039; in &#039;&#039;unittest&#039;&#039;), which you can run &#039;&#039;pytest&#039;&#039; on.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# Use your factorial function from exercise 2 in [[Making Functions]]. If you did not do so already, change it to use exceptions instead of &#039;&#039;&#039;sys.exit()&#039;&#039;&#039;, when an error occurs. Now make simple unit tests for the following test cases: 12, 2, 1, 0, -1, 3.0, 3.4, &quot;3&quot;, &quot;3.1.&quot;, &quot;ABC&quot;. The factorial function and all test functions must be in one single file (&#039;&#039;factorial_test.py&#039;&#039; in &#039;&#039;unittest&#039;&#039;), which you can run &#039;&#039;pytest&#039;&#039; on.&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# Now remove the factorial function from &#039;&#039;factorial_test.py&#039;&#039; and put it in its own file &#039;&#039;factorial.py&#039;&#039;. Import it from the &#039;&#039;factorial_test.py&#039;&#039; like &#039;&#039;&#039;from factorial import factorial&#039;&#039;&#039;. The first factorial is the name of the .py file, the second factorial is the name of your factorial function. Just run &#039;&#039;pytest&#039;&#039; (no file name) in the folder to check it works. It is more normal to have test and function separated.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# Now remove the factorial function from &#039;&#039;factorial_test.py&#039;&#039; and put it in its own file &#039;&#039;factorial.py&#039;&#039;. Import it from the &#039;&#039;factorial_test.py&#039;&#039; like &#039;&#039;&#039;from factorial import factorial&#039;&#039;&#039;. The first factorial is the name of the .py file, the second factorial is the name of your factorial function. Just run &#039;&#039;pytest&#039;&#039; (no file name) in the folder to check it works. It is more normal to have test and function separated.&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# Above we removed test code from function code by creating two files. Next, put the files in their own folder in &#039;&#039;unittest&#039;&#039;. I would put my &#039;&#039;factorial.py&#039;&#039; in &#039;&#039;unittest/src&#039;&#039; and &#039;&#039;factorial_test.py&#039;&#039; in &#039;&#039;unittest/test&#039;&#039;. This way there is a very clear separation between function and test. The problem is making sure the test code loads the function code. Do it wrong a couple of times - it is very instructive.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# Above we removed test code from function code by creating two files. Next, put the files in their own folder in &#039;&#039;unittest&#039;&#039;. I would put my &#039;&#039;factorial.py&#039;&#039; in &#039;&#039;unittest/src&#039;&#039; and &#039;&#039;factorial_test.py&#039;&#039; in &#039;&#039;unittest/test&#039;&#039;. This way there is a very clear separation between function and test. The problem is making sure the test code loads the function code. Do it wrong a couple of times - it is very instructive.&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# Follow the file structure of having a &#039;&#039;code&#039;&#039; (or &#039;&#039;src&#039;&#039;) folder for programs, a &#039;&#039;test&#039;&#039; folder for tests, and now a &#039;&#039;testdata&#039;&#039; folder for files containing test data. Now make unit tests and appropriate test data files for your &#039;&#039;&#039;fasta&#039;&#039;&#039; class from last week. In this exercise you just need to make unit test for the method &#039;&#039;&#039;load&#039;&#039;&#039;. You need to hand in both tests and test data. Maybe you should zip it all. Learn to zip :-)&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# Follow the file structure of having a &#039;&#039;code&#039;&#039; (or &#039;&#039;src&#039;&#039;) folder for programs, a &#039;&#039;test&#039;&#039; folder for tests, and now a &#039;&#039;testdata&#039;&#039; folder for files containing test data. Now make unit tests and appropriate test data files for your &#039;&#039;&#039;fasta&#039;&#039;&#039; class from last week. In this exercise you just need to make unit test for the method &#039;&#039;&#039;load&#039;&#039;&#039;. You need to hand in both tests and test data. Maybe you should zip it all. Learn to zip :-)&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# Add unit tests for the method &#039;&#039;&#039;save&#039;&#039;&#039; in your &#039;&#039;&#039;fasta&#039;&#039;&#039; class.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# Add unit tests for the method &#039;&#039;&#039;save&#039;&#039;&#039; in your &#039;&#039;&#039;fasta&#039;&#039;&#039; class.&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# Add unit tests for the method &#039;&#039;&#039;delete&#039;&#039;&#039; in your &#039;&#039;&#039;fasta&#039;&#039;&#039; class.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# Add unit tests for the method &#039;&#039;&#039;delete&#039;&#039;&#039; in your &#039;&#039;&#039;fasta&#039;&#039;&#039; class.&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;I would not be surprised if you find errors in your &amp;#039;&amp;#039;&amp;#039;fasta&amp;#039;&amp;#039;&amp;#039; class based on these tests. I found flaws in my code.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;I would not be surprised if you find errors in your &amp;#039;&amp;#039;&amp;#039;fasta&amp;#039;&amp;#039;&amp;#039; class based on these tests. I found flaws in my code.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;== Exercises for extra practice ==&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;== Exercises for extra practice ==&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# Add unit tests for all methods in your &amp;#039;&amp;#039;&amp;#039;fasta&amp;#039;&amp;#039;&amp;#039; class. That will be a bit of work.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# Add unit tests for all methods in your &amp;#039;&amp;#039;&amp;#039;fasta&amp;#039;&amp;#039;&amp;#039; class. That will be a bit of work.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id>https://teaching.healthtech.dtu.dk:443/22118/index.php?title=Beginning_unit_test&amp;diff=100&amp;oldid=prev</id>
		<title>WikiSysop: Created page with &quot;__NOTOC__ {| width=500  style=&quot;font-size: 10px; float:right; margin-left: 10px; margin-top: -56px;&quot; |Previous: Intermediate classes |Next: Intermediate unit test |} == Required course material for the lesson == Powerpoint: [https://teaching.healthtech.dtu.dk/material/22118/22118_09-Testing.ppt Testing]&lt;br&gt; Online: [https://docs.pytest.org/ pytest documentation]&lt;br&gt; Resource: Example code - Unit test&lt;br&gt; Resource: Unit test - start of reverse polish notation...&quot;</title>
		<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk:443/22118/index.php?title=Beginning_unit_test&amp;diff=100&amp;oldid=prev"/>
		<updated>2026-01-27T08:36:54Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;__NOTOC__ {| width=500  style=&amp;quot;font-size: 10px; float:right; margin-left: 10px; margin-top: -56px;&amp;quot; |Previous: &lt;a href=&quot;/22118/index.php/Intermediate_classes&quot; title=&quot;Intermediate classes&quot;&gt;Intermediate classes&lt;/a&gt; |Next: &lt;a href=&quot;/22118/index.php/Intermediate_unit_test&quot; title=&quot;Intermediate unit test&quot;&gt;Intermediate unit test&lt;/a&gt; |} == Required course material for the lesson == Powerpoint: [https://teaching.healthtech.dtu.dk/material/22118/22118_09-Testing.ppt Testing]&amp;lt;br&amp;gt; Online: [https://docs.pytest.org/ pytest documentation]&amp;lt;br&amp;gt; Resource: &lt;a href=&quot;/22118/index.php/Example_code_-_Unit_test&quot; title=&quot;Example code - Unit test&quot;&gt;Example code - Unit test&lt;/a&gt;&amp;lt;br&amp;gt; Resource: Unit test - start of reverse polish notation...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;__NOTOC__&lt;br /&gt;
{| width=500  style=&amp;quot;font-size: 10px; float:right; margin-left: 10px; margin-top: -56px;&amp;quot;&lt;br /&gt;
|Previous: [[Intermediate classes]]&lt;br /&gt;
|Next: [[Intermediate unit test]]&lt;br /&gt;
|}&lt;br /&gt;
== Required course material for the lesson ==&lt;br /&gt;
Powerpoint: [https://teaching.healthtech.dtu.dk/material/22118/22118_09-Testing.ppt Testing]&amp;lt;br&amp;gt;&lt;br /&gt;
Online: [https://docs.pytest.org/ pytest documentation]&amp;lt;br&amp;gt;&lt;br /&gt;
Resource: [[Example code - Unit test]]&amp;lt;br&amp;gt;&lt;br /&gt;
Resource: [[Unit test - start of reverse polish notation class]]&amp;lt;br&amp;gt;&lt;br /&gt;
Blog: [https://www.joelonsoftware.com/2000/04/30/top-five-wrong-reasons-you-dont-have-testers/ On testing], by the founder of StackExchange.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Subjects covered ==&lt;br /&gt;
Overview of test methods&amp;lt;br&amp;gt;&lt;br /&gt;
Unit test using pytest framework.&lt;br /&gt;
&lt;br /&gt;
== Exercises to be handed in ==&lt;br /&gt;
You should make a special folder for the exercises. I will refer to my special folder as &amp;#039;&amp;#039;unittest&amp;#039;&amp;#039; in these exercises. You will also see some &amp;#039;&amp;#039;__pycache__&amp;#039;&amp;#039; folders appear in places. This is Pythons cache for &amp;quot;compiled&amp;quot; programs. It is safe to ignore and also to delete, because it may become outdated.&lt;br /&gt;
# Use your factorial function from exercise 2 in [[Making Functions]]. If you did not do so already, change it to use exceptions instead of &amp;#039;&amp;#039;&amp;#039;sys.exit()&amp;#039;&amp;#039;&amp;#039;, when an error occurs. Now make simple unit tests for the following test cases: 12, 2, 1, 0, -1, 3.0, 3.4, &amp;quot;3&amp;quot;, &amp;quot;3.1.&amp;quot;, &amp;quot;ABC&amp;quot;. The factorial function and all test functions must be in one single file (&amp;#039;&amp;#039;factorial_test.py&amp;#039;&amp;#039; in &amp;#039;&amp;#039;unittest&amp;#039;&amp;#039;), which you can run &amp;#039;&amp;#039;pytest&amp;#039;&amp;#039; on.&lt;br /&gt;
# Now remove the factorial function from &amp;#039;&amp;#039;factorial_test.py&amp;#039;&amp;#039; and put it in its own file &amp;#039;&amp;#039;factorial.py&amp;#039;&amp;#039;. Import it from the &amp;#039;&amp;#039;factorial_test.py&amp;#039;&amp;#039; like &amp;#039;&amp;#039;&amp;#039;from factorial import factorial&amp;#039;&amp;#039;&amp;#039;. The first factorial is the name of the .py file, the second factorial is the name of your factorial function. Just run &amp;#039;&amp;#039;pytest&amp;#039;&amp;#039; (no file name) in the folder to check it works. It is more normal to have test and function separated.&lt;br /&gt;
# Above we removed test code from function code by creating two files. Next, put the files in their own folder in &amp;#039;&amp;#039;unittest&amp;#039;&amp;#039;. I would put my &amp;#039;&amp;#039;factorial.py&amp;#039;&amp;#039; in &amp;#039;&amp;#039;unittest/src&amp;#039;&amp;#039; and &amp;#039;&amp;#039;factorial_test.py&amp;#039;&amp;#039; in &amp;#039;&amp;#039;unittest/test&amp;#039;&amp;#039;. This way there is a very clear separation between function and test. The problem is making sure the test code loads the function code. Do it wrong a couple of times - it is very instructive.&lt;br /&gt;
# Follow the file structure of having a &amp;#039;&amp;#039;code&amp;#039;&amp;#039; (or &amp;#039;&amp;#039;src&amp;#039;&amp;#039;) folder for programs, a &amp;#039;&amp;#039;test&amp;#039;&amp;#039; folder for tests, and now a &amp;#039;&amp;#039;testdata&amp;#039;&amp;#039; folder for files containing test data. Now make unit tests and appropriate test data files for your &amp;#039;&amp;#039;&amp;#039;fasta&amp;#039;&amp;#039;&amp;#039; class from last week. In this exercise you just need to make unit test for the method &amp;#039;&amp;#039;&amp;#039;load&amp;#039;&amp;#039;&amp;#039;. You need to hand in both tests and test data. Maybe you should zip it all. Learn to zip :-)&lt;br /&gt;
# Add unit tests for the method &amp;#039;&amp;#039;&amp;#039;save&amp;#039;&amp;#039;&amp;#039; in your &amp;#039;&amp;#039;&amp;#039;fasta&amp;#039;&amp;#039;&amp;#039; class.&lt;br /&gt;
# Add unit tests for the method &amp;#039;&amp;#039;&amp;#039;delete&amp;#039;&amp;#039;&amp;#039; in your &amp;#039;&amp;#039;&amp;#039;fasta&amp;#039;&amp;#039;&amp;#039; class.&lt;br /&gt;
I would not be surprised if you find errors in your &amp;#039;&amp;#039;&amp;#039;fasta&amp;#039;&amp;#039;&amp;#039; class based on these tests. I found flaws in my code.&lt;br /&gt;
&lt;br /&gt;
== Exercises for extra practice ==&lt;br /&gt;
# Add unit tests for all methods in your &amp;#039;&amp;#039;&amp;#039;fasta&amp;#039;&amp;#039;&amp;#039; class. That will be a bit of work.&lt;/div&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
</feed>