Presentation is loading. Please wait.

Presentation is loading. Please wait.

Testing It is much better to have a plan when testing your programs than it is to just randomly try values in a haphazard fashion. Testing Strategies:

Similar presentations


Presentation on theme: "Testing It is much better to have a plan when testing your programs than it is to just randomly try values in a haphazard fashion. Testing Strategies:"— Presentation transcript:

1 Testing It is much better to have a plan when testing your programs than it is to just randomly try values in a haphazard fashion. Testing Strategies: – White-box Testing – Black-box Testing

2 White-box Testing White-box Testing: – We know the implementation details (how) – Tests the method based on covering all code branches (paths) – Branch – A code segment that is not always executed if-else statement switch statement while Why we avoid break and continue statements – Path – combination of branches that might be traversed when a program is executed Create test cases that test the various branches or paths. For large software projects, achieving 100% path coverage is often not a feasible goal.

3 Black-box Testing Black-box Testing: – We know the specification of the method (what) – Given an input we know what the output should be. Thus, treating the method as a “black box” – We do not know the implementation details (how) Impossible to test your program for every possible input value. First determine the possible input categories. E.g., – expected values – boundary values – out of range values – illegal values What should be your black box test plan if you prompt the user for an integer between 1 and 1000?

4 Preconditions and Postconditions A precondition is a statement of any assumptions or constraints on the input parameters before a method begins execution A postcondition describes the result of executing the method, including any change to the object’s state A method's preconditions and postconditions serve as a contract between a method caller and the method programmer /** Pre: this.grid must contain a cell in position [i][j] Post: returns a count of the number of neighbors of cell[i][j] that are infected. */ public int neighborsInfected(int i, int j){ … }

5 Unit Testing with Drivers A driver program – declares any necessary object instances and variables – assigns values to any of the method's inputs (specified by the preconditions) – calls the method – displays the outputs returned by the method Driver code is placed in a main method (usually in a separate class called TestingMyClass)

6 Test Driver ArrayList public static void main(String[] args) { // Create ArrayList ArrayList myList = new ArrayList(); myList.add("Barb"); myList.add("Mary"); myList.add("Liz"); myList.add("Barb"); myList.add("Mary"); // Test indexOf() method if (myList.indexOf(“Barb”) == 0) System.out.println ("SUCCESS – indexOf() first element"); else System.out.println ("FAILURE – indexOf() first element"); if (myList.indexOf(“Fred”) == -1) System.out.println ("SUCCESS – indexOf() element not in the list"); else System.out.println ("FAILURE – indexOf() element not in the list");


Download ppt "Testing It is much better to have a plan when testing your programs than it is to just randomly try values in a haphazard fashion. Testing Strategies:"

Similar presentations


Ads by Google