<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://teaching.healthtech.dtu.dk/22113/index.php?action=history&amp;feed=atom&amp;title=Unit_test</id>
	<title>Unit test - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://teaching.healthtech.dtu.dk/22113/index.php?action=history&amp;feed=atom&amp;title=Unit_test"/>
	<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk/22113/index.php?title=Unit_test&amp;action=history"/>
	<updated>2026-04-07T14:45:40Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.41.0</generator>
	<entry>
		<id>https://teaching.healthtech.dtu.dk/22113/index.php?title=Unit_test&amp;diff=120&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/22113/index.php?title=Unit_test&amp;diff=120&amp;oldid=prev"/>
		<updated>2025-03-24T13:48:12Z</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 15:48, 24 March 2025&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-l8&quot;&gt;Line 8:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 8:&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;Online: [https://docs.pytest.org/ pytest documentation]&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;Online: [https://docs.pytest.org/ pytest documentation]&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: [[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 colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&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;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;Resource: [[Unit test - start of reverse polish notation class]]&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;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;/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;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;/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;/table&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id>https://teaching.healthtech.dtu.dk/22113/index.php?title=Unit_test&amp;diff=36&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: Classes |Next: Scientific Libraries, Pandas, Numpy |} == Required course material for the lesson == Powerpoint: [https://teaching.healthtech.dtu.dk/material/22113/22113_08-Testing.ppt Testing]&lt;br&gt; Online: [https://docs.pytest.org/ pytest documentation]&lt;br&gt; Resource: Example code - Unit test&lt;br&gt; Blog: [https://www.joelonsoftware.com/2000/04/30/top-fiv...&quot;</title>
		<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk/22113/index.php?title=Unit_test&amp;diff=36&amp;oldid=prev"/>
		<updated>2024-03-06T14:04:52Z</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;/22113/index.php/Classes&quot; title=&quot;Classes&quot;&gt;Classes&lt;/a&gt; |Next: &lt;a href=&quot;/22113/index.php/Scientific_Libraries,_Pandas,_Numpy&quot; title=&quot;Scientific Libraries, Pandas, Numpy&quot;&gt;Scientific Libraries, Pandas, Numpy&lt;/a&gt; |} == Required course material for the lesson == Powerpoint: [https://teaching.healthtech.dtu.dk/material/22113/22113_08-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;/22113/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; Blog: [https://www.joelonsoftware.com/2000/04/30/top-fiv...&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: [[Classes]]&lt;br /&gt;
|Next: [[Scientific Libraries, Pandas, Numpy]]&lt;br /&gt;
|}&lt;br /&gt;
== Required course material for the lesson ==&lt;br /&gt;
Powerpoint: [https://teaching.healthtech.dtu.dk/material/22113/22113_08-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;
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>