{"id":1320,"date":"2018-02-05T22:05:25","date_gmt":"2018-02-05T22:05:25","guid":{"rendered":"https:\/\/old.staging-teachcomputerscienceuk.kinsta.cloud\/?p=1320"},"modified":"2024-07-24T11:14:53","modified_gmt":"2024-07-24T11:14:53","slug":"testing-your-code","status":"publish","type":"post","link":"https:\/\/teachcomputerscience.com\/testing-your-code\/","title":{"rendered":"Testing Your Code"},"content":{"rendered":"<div class=\"gb-container gb-container-5438aa3d upsell-block\"><div class=\"gb-inside-container\">\n<div class=\"gb-grid-wrapper gb-grid-wrapper-228d9d26\">\n<div class=\"gb-grid-column gb-grid-column-a3192279\"><div class=\"gb-container gb-container-a3192279\"><div class=\"gb-inside-container\">\n\n<h2 class=\"gb-headline gb-headline-18a1dd4f gb-headline-text\">KS3 Testing and Validation (14-16 years)<\/h2>\n\n\n\n<ul class=\"wp-block-list\"><li>An editable PowerPoint lesson presentation<\/li><li>Editable revision handouts<\/li><li>A glossary which covers the key terminologies of the module<\/li><li>Topic mindmaps for visualising the key concepts<\/li><li>Printable flashcards to help students engage active recall and confidence-based repetition<\/li><li>A quiz with accompanying answer key to test knowledge and understanding of the module<\/li><\/ul>\n\n\n<div class=\"gb-button-wrapper gb-button-wrapper-4da702cb\">\n\n<a class=\"gb-button gb-button-1116943f gb-button-text\" href=\"https:\/\/teachcomputerscience.com\/ks3\/programming\/testing-and-validation\/\">View KS3 Testing and Validation Resources<\/a>\n\n<\/div>\n<\/div><\/div><\/div>\n\n<div class=\"gb-grid-column gb-grid-column-82b276af\"><div class=\"gb-container gb-container-82b276af\"><div class=\"gb-inside-container\">\n\n<h2 class=\"gb-headline gb-headline-2aaab871 gb-headline-text\">A-Level Software Development Lifecycle (16-18 years)<\/h2>\n\n\n\n<ul class=\"wp-block-list\"><li>An editable PowerPoint lesson presentation<\/li><li>Editable revision handouts<\/li><li>A glossary which covers the key terminologies of the module<\/li><li>Topic mindmaps for visualising the key concepts<\/li><li>Printable flashcards to help students engage active recall and confidence-based repetition<\/li><li>A quiz with accompanying answer key to test knowledge and understanding of the module<\/li><\/ul>\n\n\n<div class=\"gb-button-wrapper gb-button-wrapper-3bd7515b\">\n\n<a class=\"gb-button gb-button-bfcab68a gb-button-text\" href=\"https:\/\/teachcomputerscience.com\/a-level\/software\/software-development-lifecycle\/\">View A-Level Software Development Lifecycle Resources<\/a>\n\n<\/div>\n<\/div><\/div><\/div>\n<\/div>\n<\/div><\/div>\n\n\n\n\n<p>Candidates should be able to:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>describe syntax errors and logic errors which may occur while developing a program<\/li><li>understand and identify syntax and logic errors<\/li><li>select and justify test data for a program, stating the expected outcome of each test.<\/li><\/ul>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">What are syntax errors?<\/h2>\n\n\n\n<p>Syntax errors are errors that occur when instructions do not follow the <strong>rules<\/strong> or the <strong>grammar<\/strong> of the programming language. The instruction cannot, therefore, be executed and an error message will usually be generated. That is why testing your code is important. Examples of syntax errors include:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Spelling errors with <strong>keywords<\/strong><br>i.e.\n<p>&nbsp;<\/p>\n<pre>PENCOLO<strong>U<\/strong>R = \"#00FF00\"<\/pre>\n<p>instead of<\/p>\n<pre>PENCOLOR = \"#00FF00\"<\/pre>\n<\/li><li>Spelling errors with <strong>variables<\/strong><br>i.e.\n<p>&nbsp;<\/p>\n<pre>max_value = 100,&nbsp;<\/pre>\n<pre>PRINT maxvalue<\/pre>\n<\/li><li>Missing or extra <strong>brackets or separators<\/strong> in an instruction.<br>i.e.\n<p>&nbsp;<\/p>\n<pre>IF(answer=\"True\"<strong>,,<\/strong>\"Correct\",\"Wrong\"<strong>))<\/strong><\/pre>\n<\/li><li>Missing <strong>arguments<\/strong> in an instruction.<br>i.e.\n<p>&nbsp;<\/p>\n<pre>DRAWRECTANGLE(50,50)<\/pre>\n<p>should be<\/p>\n<pre>DRAWRECTANGLE(50,50,200,400)<\/pre>\n<\/li><li><strong>Not closing iteration loops<\/strong> correctly.<br>i.e. missing the ENDWHILE from a WHILE \/ ENDWHILE loop.<\/li><li><strong>Not putting double quotes around text<\/strong> so the program assumes the text is a variable.<br>i.e.\n<p>&nbsp;<\/p>\n<pre>PRINT Hello World<\/pre>\n<\/li><\/ul>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Testing your code: What are logic errors?<\/h2>\n\n\n\n<p>Logic errors do not stop a program from running or producing error messages but will result in <strong>a program not running in the way it was expected to<\/strong>. Examples of logic errors include:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Errors in a mathematical formula.<br>i.e.\n<p>&nbsp;<\/p>\n<pre>result = (total + step) * 12<\/pre>\n<p>will sometimes produce a different result to<\/p>\n<pre>result = total + (step * 12)<\/pre>\n<p>or<\/p>\n<pre>result = total + step * 12<\/pre>\n<\/li><li>Sequential instructions in the wrong order.<br>i.e.\n<p>&nbsp;<\/p>\n<pre>count = count + 1\nPRINT count<\/pre>\n<p>VS<\/p>\n<pre>PRINT count\ncount = count + 1<\/pre>\n<\/li><li>The wrong conditions being set in iteration loops so the loop does not repeat the expected number of times.<\/li><li>The wrong conditions being set in conditional instructions.<br>i.e.\n<p>&nbsp;<\/p>\n<pre>IF A &gt; 100<\/pre>\n<p>rather than<\/p>\n<pre>IF A &gt;= 100<\/pre>\n<p>or using ELSE instead of ELSEIF.<\/p>\n<\/li><li>Referring to variables that have not been set correctly.<br>i.e.\n<p>&nbsp;<\/p>\n<pre>count = count + step<\/pre>\n<p>when step has not previously been assigned a value.<\/p>\n<\/li><li>Type mismatch errors.<br>i.e. trying to add number variables but having the program treat them as text:\n<p>&nbsp;<\/p>\n<pre>num1 = 9, num2 = 9, PRINT num1 + num2<\/pre>\n<p>gives 99 rather than 18.<\/p>\n<\/li><\/ul>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">What is test data?<\/h2>\n\n\n\n<p>Testing is carried out once syntax and logic errors have been corrected and a program appears to be running correctly. Testing should cover as many types of input\/processing\/output data and program operation as possible. It is important to try and &#8216;break&#8217; the program, not simply to show that it works is the right values are input.<br>Typical test input data can include:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>Normal data<\/strong> &#8211; data that should be <strong>accepted<\/strong><\/li><li><strong>Borderline\/extreme data<\/strong> &#8211; data that tests the <strong>limit<\/strong> of what should be accepted, i.e. just above, just below and actually on the limit<\/li><li><strong>Erroneous data<\/strong> &#8211; data that should be <strong>rejected<\/strong><\/li><\/ul>\n\n\n\n<p>A <strong>test plan<\/strong> is made up of the <strong>test data<\/strong>, the <strong>justification<\/strong> for the test and the <strong>expected<\/strong> test outcome. A test plan is often in the form of a table such as an example below:<\/p>\n\n\n\n<figure class=\"wp-block-table rcp-table\"><table><tbody><tr><th>Test data<\/th><th>Validation rule being tested<\/th><th>Test type<\/th><th>Expected result<\/th><th>Actual result<\/th><\/tr><tr><td>Mrs<\/td><td>Title field member <strong>list check<\/strong><br>(Mr, Mrs, Miss, Ms, Dr)<\/td><td>Normal<\/td><td>Data accepted<\/td><td>&nbsp;<\/td><\/tr><tr><td>Mz<\/td><td>Title field member <strong>list check<\/strong><br>(Mr, Mrs, Miss, Ms, Dr)<\/td><td>Erroneous<\/td><td>Data rejected with a suitable error message<\/td><td>&nbsp;<\/td><\/tr><tr><td>10<\/td><td>Title field member <strong>list check<\/strong><br>(Mr, Mrs, Miss, Ms, Dr)<\/td><td>Erroneous<\/td><td>Data rejected with an error message<\/td><td>&nbsp;<\/td><\/tr><tr><td>10<\/td><td>Staff discount <strong>range check<\/strong><br>(between 1 and 20)<\/td><td>Normal<\/td><td>Data accepted<\/td><td>&nbsp;<\/td><\/tr><tr><td>-2<\/td><td>Staff discount <strong>range check <\/strong><br>(between 1 and 20)<\/td><td>Erroneous<\/td><td>Data rejected with a suitable error message<\/td><td>&nbsp;<\/td><\/tr><tr><td>20<\/td><td>Staff discount <strong>range check <\/strong><br>(between 1 and 20)<\/td><td>Borderline<\/td><td>Data accepted<\/td><td>&nbsp;<\/td><\/tr><tr><td>20.01<\/td><td>Staff discount <strong>range check<\/strong><br>(between 0 and 20)<\/td><td>Borderline<\/td><td>Data rejected with a suitable error message<\/td><td>&nbsp;<\/td><\/tr><tr><td>19.99<\/td><td>Staff discount <strong>range check <\/strong><br>(between 1 and 20)<\/td><td>Borderline<\/td><td>Data accepted<\/td><td>&nbsp;<\/td><\/tr><tr><td>Ten<\/td><td>Staff discount <strong>data type check <\/strong>(between 1 and 20)<\/td><td>Erroneous<\/td><td>Data rejected with a suitable error message<\/td><td>&nbsp;<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 class=\"gb-headline gb-headline-d4500338 gb-headline-text\">Further Readings:<\/h3>\n\n\n\n<ul class=\"wp-block-list\"><li><a href=\"https:\/\/en.wikipedia.org\/wiki\/Syntax_(programming_languages)\" target=\"_blank\" rel=\"noopener\">Syntax (programming languages)<\/a><\/li><\/ul>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/teachcomputerscience.com\/wp-content\/uploads\/2019\/08\/031-edit-code.png\" alt=\"Logic errors do not stop a program from running or producing error messages but will result in a program not running in the way it was expected to. This is why testing your code is important\" class=\"wp-image-5753\" width=\"341\" height=\"341\" title=\"\"><\/figure><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Candidates should be able to: describe syntax errors and logic errors which may occur while developing a program understand and identify syntax and logic errors select and justify test data for a program, stating the expected outcome of each test. What are syntax errors? Syntax errors are errors that occur when instructions do not follow &#8230; <\/p>\n<p class=\"read-more-container\"><a title=\"Testing Your Code\" class=\"read-more button\" href=\"https:\/\/teachcomputerscience.com\/testing-your-code\/\" aria-label=\"More on Testing Your Code\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_generate-full-width-content":"","_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[14],"tags":[204,47],"class_list":["post-1320","post","type-post","status-publish","format-standard","hentry","category-programming","tag-article","tag-hide-old-upsell","generate-columns","tablet-grid-50","mobile-grid-100","grid-parent","grid-50"],"acf":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/teachcomputerscience.com\/wp-json\/wp\/v2\/posts\/1320","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/teachcomputerscience.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/teachcomputerscience.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/teachcomputerscience.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/teachcomputerscience.com\/wp-json\/wp\/v2\/comments?post=1320"}],"version-history":[{"count":2,"href":"https:\/\/teachcomputerscience.com\/wp-json\/wp\/v2\/posts\/1320\/revisions"}],"predecessor-version":[{"id":607055,"href":"https:\/\/teachcomputerscience.com\/wp-json\/wp\/v2\/posts\/1320\/revisions\/607055"}],"wp:attachment":[{"href":"https:\/\/teachcomputerscience.com\/wp-json\/wp\/v2\/media?parent=1320"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/teachcomputerscience.com\/wp-json\/wp\/v2\/categories?post=1320"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/teachcomputerscience.com\/wp-json\/wp\/v2\/tags?post=1320"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}