Presentation is loading. Please wait.

Presentation is loading. Please wait.

CSIS 3701: Advanced Object Oriented Programming

Similar presentations


Presentation on theme: "CSIS 3701: Advanced Object Oriented Programming"— Presentation transcript:

1 CSIS 3701: Advanced Object Oriented Programming
Regression Testing CSIS 3701: Advanced Object Oriented Programming

2 Class Drivers in Java public static void main(String[] args) {
Example: Simple driver for add method in NameList public static void main(String[] args) { NameList n = new NameList(3); while(true) { String name = JOptionPane.showInputDialog(null, "Enter name"); n.add(name); JOptionPane.showMessageDialog(null, n.toString()); }

3 Class Drivers in Java public static void main(String[] args) {
May need additional code for exceptions public static void main(String[] args) { NameList n = new NameList(3); while(true) { String name = JOptionPane.showInputDialog(null, “Name:"); try {n.add(name);} catch (FullListException ex) { JOptionPane.showMessageDialog(null, "List full!"); } catch (InListException ex) { JOptionPane.showMessageDialog(null, “In list!"); JOptionPane.showMessageDialog(null, n.toString());

4 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? Module A tested first Fixing B creates bugs in A If A not retested, will be shipped with bugs! Module B tested second

5 Regression Testing Regression testing: Retesting with all test cases after any change to code Problem: May be thousands of tests! Too many for interactive debugging Comprehensive list of test cases Fix bugs Retest with all test cases Find bugs

6 Automated Testing Goal: Automate comprehensive testing Approaches:
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)

7 Scripted Testing For each constructor/void method: Execute method
Display value returned/exception thrown Get current state to desired state (using toString() ) Display current state Compare to desired state Error message if incorrect Display actual state

8 Scripted Testing Example
public static void main(String[] args) { // Test default constructor Clock c1 = new Clock(); if (!(c1.toString()).equals("00:00")) System.out.println("Default constructor failure:" c1.toString()); // Test parameterized constructor Clock c2 = new Clock(12,34); if (!(c2.toString()).equals("12:34")) System.out.println("Parameter constructor failure:" c2.toString());

9 Scripted Testing Example
// Test ability to set new time c2.setTime(9,1); if (!(c2.toString()).equals("09:01")) System.out.println("setTime failure: "+c2.toString()); // Test ability of nextMinute to increment minute, hour Clock c3 = new Clock(11, 59); c3.nextMinute(); if (!(c3.toString()).equals("12:00")) System.out.println("next failure: "+c3.toString()); Clock c4 = new Clock(23, 59); c4.nextMinute(); if (!(c4.toString()).equals("00:00")) System.out.println("next failure: "+c4.toString());

10 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 (c2.getHour() != 9) System.out.println("getHour failure: "+c2.getHour()); if (!(c2.toString()).equals("09:01")) System.out.println("getHour changed state: " c2.toString());

11 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

12 Scripted Testing Example
// Test validation inspectors for border cases if (c2.isHour(-1)) System.out.println("isHour failure: -1"); if (!c2.isHour(0)) System.out.println("isHour failure: 0"); if (c2.isHour(24)) System.out.println("isHour failure: 24"); if (!c2.isHour(23)) System.out.println("isHour failure: 23");

13 Scripted Testing Example
// Test validation in modifiers for no state change c2.setTime(-1,12); if (!(c2.toString()).equals("09:01")) System.out.println("setTime validation failure: " c2.toString()); c2.setTime(24,12); System.out.println("setTime validation failure: " c2.toString());


Download ppt "CSIS 3701: Advanced Object Oriented Programming"

Similar presentations


Ads by Google