Testing Testing Types of Errors Test Data Dry running Program Trace table What is Testing? Testing is the process of finding errors within the software. Testing can be carried out at all stages of the system development lifecycle At each stage a certain test will be carried out This makes sure the software is working as you would like it to Test Plan Before you start testing something you will have what is called a test plan The plan will describes each item that needs to be tested The test plan provides ◦ instructions to be carried out ◦ test data (inputs) ◦ the expected outcomes The set of test data and expected outcomes form a test case. Types of Testing There are a various number of techniques that can be applied that help select a test case that will find the largest number of errors The two techniques we will be looking at are 1. Black Box techniques 2. White Box techniques. Black Box Technique Black box techniques see the software as a ‘black box’ which has inputs and outputs No understanding of what is happening within the black box is needed When testing, suitable inputs are selected based upon the running of the system White Box Techniques White box techniques analyse the structure and logic of the program. This is then used both to help monitor the detail of testing and to guide the selecting of appropriate test data Errors Errors are a fault or a mistake in a program that causes the program to produce wrong results or not to work at all Most computers attempt to indicate the source of an error by producing error messages There are many different types of errors that could be found Syntax Errors Syntax errors are caused by forgetting certain codes and statement structures of the programming language being used The program will not understand some statements because they do not obey the programming language’s rules The compiler will find these errors There can be various types of syntax errors, and the following are some syntax errors examples using JAVA. Examples Code Syntax Error System.out.plintln(“Hello”); prlintln is misspelt. public static void main (String args[]){ In this case, the syntax error is class test{ caused by the misplacement of statements, because class must } appear before public static void } main… … Here, the syntax error is the if (x>5) System.out.println(“Bigger”) omission of the ; at the end of the println statement. Logical Errors A logical error is a mistake found in the actual design of a program An example is a branch to a wrong statement or the use of the wrong mathematical operation Logical errors can be found by gaining the wrong results The compiler does not notice these errors Examples Logical Error Code Average=5+10+3/3; Here, the average will be worked out incorrectly because 5+10+3 is not enclosed in brackets, hence the result will not be correct but it will be still worked out. if (x>5) System.out.println (“X is smaller than 5“); In this case, the logical error is in the because println it will statement display the incorrect message since if x>5 the correct message will be X is bigger than 5. Run Time Errors Run time errors are errors which are shown when the program is actually running Examples; 1. Division by Zero is caused when the program tries to divide something by 0 2. Lack of Memory, this occurs when the program requires more memory than there is available hence it will not be able to function properly. 3. External Errors, such as an error in printing, because no printer could be found or it is turned off. 4. Unusual Data, which can occur when the user enters incorrect data. For example, if the user is asked to input a few numbers to add them up, and letters are entered, a runtime error will occur, because letters cannot be added. Run Time errors can be prevented by writing statements to control them. For example, if the user needs to enter numbers, and the user enters letters, the program should be able to identify this and let the user know Test Data When we test our programs we should first create a test plan where the possible values to be tested are listed down Then we would go through the test plan to be able to test different areas of the program. For example, if the program asks the user to enter his/her name there would be various test data which we can be use; 1. 2. 3. 4. Entering the actual name, Leaving it blank, Entering numbers instead of letters, Entering a single letter. Test Data All the possible answers will be tested by providing the inputs above Dry Running Dry running a program is basically working through a section of a program manually. Dry running a program is useful for finding run-time errors A dry one is done in parts by taking one section of the program at a time and not the whole program all at once A program trace table is produced before the dry run starts, this table contains; ◦ A column showing the instruction executed ◦ columns for the contents of each variable Trace table The programmer uses the instructions from the trace table, adding a new line to the trace table each time an instruction is run. The new line of the trace table shows the instruction (by its line number, and show any changes to the variables) Example Statement H W A 1: Input H 5 2: Input W 5 15 3:A=H*W 5 15 75 4: Print A 5 15 75 5: GoTo 2 5 15 75 Output Comment Get Height Get Width Calculate Area 75 Print Area Go back for new pair values. This is the error, this line should be GoTo 1/ 2: Input W 5 20 75 3:A=H*W 5 20 100 Get Width = we haven’t updated the height