70de95e145463c3fac9ae451afca7a29.ppt
- Количество слайдов: 13
Regression Testing CSIS 3701: Advanced Object Oriented Programming
Class Drivers in Java • Example: Simple driver for add method in Name. List public static void main(String[] args) { Name. List n = new Name. List(3); while(true) { String name = JOption. Pane. show. Input. Dialog(null, "Enter name"); n. add(name); JOption. Pane. show. Message. Dialog(null, n. to. String()); } }
Class Drivers in Java • May need additional code for exceptions public static void main(String[] args) { Name. List n = new Name. List(3); while(true) { String name = JOption. Pane. show. Input. Dialog(null, “Name: "); try {n. add(name); } catch (Full. List. Exception ex) { JOption. Pane. show. Message. Dialog(null, "List full!"); } catch (In. List. Exception ex) { JOption. Pane. show. Message. Dialog(null, “In list!"); } JOption. Pane. show. Message. Dialog(null, n. to. String()); }
Regression Testing • Problem: Fixing bugs can introduce other errors – 10% to 20% of bug fixes create new bugs – Often happens as part of maintenance • Developer who changes one module not familiar with rest of system – Big problem: What if new bugs in code already tested? Fixing B creates bugs in A Module A tested first Module B tested second If A not retested, will be shipped with bugs!
Regression Testing • Regression testing: Retesting with all test cases after any change to code Retest with all test cases Fix bugs Find bugs • Problem: May be thousands of tests! – Too many for interactive debugging Comprehensive list of test cases
Automated Testing • Goal: Automate comprehensive testing – Run all test cases – Notify developer of incorrect results • Approaches: – Creating testing “script” in driver – Read test cases and desired results from file – Use testing tools (JUnit)
Scripted Testing • For each constructor/void method: – Execute method – Display value returned/exception thrown – Get current state to desired state (using to. String() ) • Display current state • Compare to desired state – Error message if incorrect • Display actual state
Scripted Testing Example public static void main(String[] args) { // Test default constructor Clock c 1 = new Clock(); if (!(c 1. to. String()). equals("00: 00")) System. out. println("Default constructor failure: " +c 1. to. String()); // Test parameterized constructor Clock c 2 = new Clock(12, 34); if (!(c 2. to. String()). equals("12: 34")) System. out. println("Parameter constructor failure: " +c 2. to. String());
Scripted Testing Example // Test ability to set new time c 2. set. Time(9, 1); if (!(c 2. to. String()). equals("09: 01")) System. out. println("set. Time failure: "+c 2. to. String()); // Test ability of next. Minute to increment minute, hour Clock c 3 = new Clock(11, 59); c 3. next. Minute(); if (!(c 3. to. String()). equals("12: 00")) System. out. println("next failure: "+c 3. to. String()); Clock c 4 = new Clock(23, 59); c 4. next. Minute(); if (!(c 4. to. String()). equals("00: 00")) System. out. println("next failure: "+c 4. to. String());
Scripted Testing for Inspectors • For each method that returns a value: – Execute method – Compare actual return value to desired value – Compare actual state to desired state • Make sure state not changed for inspectors // Test getter inspectors, make sure state not changed if (c 2. get. Hour() != 9) System. out. println("get. Hour failure: "+c 2. get. Hour()); if (!(c 2. to. String()). equals("09: 01")) System. out. println("get. Hour changed state: " +c 2. to. String());
Scripted testing for Validation • For each validation inspector: – Run test case to get value (true or false) – Compare to desired value • For each validation case in modifier: – Run test case – Make sure state not changed
Scripted Testing Example // Test validation inspectors if (c 2. is. Hour(-1)) System. out. println("is. Hour if (!c 2. is. Hour(0)) System. out. println("is. Hour if (c 2. is. Hour(24)) System. out. println("is. Hour if (!c 2. is. Hour(23)) System. out. println("is. Hour for border cases failure: -1"); failure: 0"); failure: 24"); failure: 23");
Scripted Testing Example // Test validation in modifiers for no state change c 2. set. Time(-1, 12); if (!(c 2. to. String()). equals("09: 01")) System. out. println("set. Time validation failure: " +c 2. to. String()); c 2. set. Time(24, 12); if (!(c 2. to. String()). equals("09: 01")) System. out. println("set. Time validation failure: " +c 2. to. String());
70de95e145463c3fac9ae451afca7a29.ppt