Testing
Before a program is released to a customer, a programmer needs to make sure that it runs correctly. How should this be done? Currently, your technique is to run your program once of twice and make sure it doesn't crash. If you had thousand lines of code, then there is no way that you could claim that the program is perfect after you run it 1 or 2 times. Instead you would need a more _____________ testing technique.
The purpose of testing is to produce a _________________ and ____________________ _______________________. In industry testing is done by _______________________ than those that write the program. It is hard to find errors in your own work.
A good, simple, systematic way to find lots of bugs in your programs is to do _________ and __________________ testing. We test _____________ at a time and make sure each one works before moving on.
Black Box Testing
- look only at the pre and post conditions and not at the code
- make sure that your test data doesn't break the _______________
- the test is passed if it meets the ________________.
Test the method by sending in the following kinds of parameters:
| Test Type |
Description |
| normal values that we would use often. |
|
| values that are much larger than usual. |
|
| values that are much smaller than usual. negative number and decimal numbers work well here. |
|
| strange values that people don't normally consider. Some common examples: -1, 0, 1 work well for integers. Numbers at the edge of the pre conditions. The year 2000. Sending all the same values to a function that finds the minimum. |
White Box Testing
- look at the code
- make sure that you run every line of code at least once
- test is passed if the _________________
To Test loops:
- _______________________________
- _______________________________
- _______________________________
To Test ifs:
- __________________________
Create a Test Plan for the Following Program
import java.io.*;import java.math.*;
public class fred
{
public static void main (String args[])
{System.out.println ("The max of 1, 2, and 3 is " + maxof3(1,2,3));
printstar(9);
printmultiple(5);
System.out.println("The cube of 3 is " + cube(3));
if (greater5(6)) System.out.println ("6 is greater than 5");
else System.out.println("6 is less than 5");
}
public static int maxof3 (int a, int b, int c)
{ //Pre: none
//Post: returns the largest of a,
// b or c
if (a>b && a>c)
return a;
else if (b>c && b>a)
return b;
else
return c;
}
public static void printstar (int a)
{ //Pre: a is 0 or larger
//Post: prints out a number of stars
while (a>0)
{ System.out.println("*");
a--;
}
}
public static void printmultiple (int a)
{ //Pre: none
//Post: prints out result of a X 1,
// a X 2, ... a X 10
int b = 1;
while (b < 11)
{ System.out.println(a + " X " + b
+ " = " + (a*b));
b++;
}
}
public static double cube (double a)
{ //Pre: none
//Post: returns a*a*a
return a*a*a;
}
public static boolean greater5 (int a)
{ //Pre: none
//Post: returns false if a is less
// than 5, true otherwise
if (a>5)
return true;
else
return false;
}
}
Black Box Test Cases
| Function |
Type |
Value of Parameters |
Result |
Passed? |
| Maxof3 |
Average |
|||
| Maxof3 |
Large |
|||
| Maxof3 |
Small |
|||
| Maxof3 |
Boundary |
|||
| PrintStar |
Average |
|||
| PrintStar |
Large |
|||
| PrintStar |
Small |
|||
| PrintStar |
Boundary |
|||
| PrintMultiple |
Average |
|||
| PrintMultiple |
Large |
|||
| PrintMultiple |
Small |
|||
| PrintMultiple |
Boundary |
|||
| Cube |
Average |
|||
| Cube |
Large |
|||
| Cube |
Small |
|||
| Cube |
Boundary |
|||
| Greater5 |
Average |
|||
| Greater5 |
Large |
|||
| Greater5 |
Small |
|||
| Greater5 |
Boundary |
White Box Test Cases
Maxof3 (If, so test every line)
| Line Tested |
Parameters |
Result |
Passed? |
PrintStar (Loop)
| Loop Test |
Parameters |
Result |
Passed? |
| Avoid Loop |
|||
| Loop once |
|||
| Many times |
PrintMultiple (Loop)
| Loop Test |
Parameters |
Result |
Passed? |
| Avoid Loop |
|||
| Loop once |
|||
| Many times |
Cube (no loop, no if, so just run every line)
| Line Tested |
Parameters |
Result |
Passed? |
Greater5 (if, so test every line)
| Line Tested |
Parameters |
Result |
Passed? |