Presentation is loading. Please wait.

Presentation is loading. Please wait.

Testing & Debugging CSC 171 FALL 2004 LECTURE 13.

Similar presentations


Presentation on theme: "Testing & Debugging CSC 171 FALL 2004 LECTURE 13."— Presentation transcript:

1 Testing & Debugging CSC 171 FALL 2004 LECTURE 13

2 Reading Read Chapter 8 of Horstmann We will be doing this in labs

3 BUGS?

4 TERMINOLOGY Using the term “fault” instead of “bug” is one step toward professionalism

5 Therac-25

6 PATRIOT MISSILE On February 25, 1991, a Patriot missile defense system operating at Dhahran, Saudi Arabia, during Operation Desert Storm failed to track and intercept an incoming Scud. This Scud subsequently hit an Army barracks, killing 28 Americans. The Patriot battery at Dhahran failed to track and intercept the Scud missile because of a software problem in the system's weapons control computer.

7 UNIT TESTING Test classes in isolation, outside the program in which they are used Test one class at a time Supply test inputs through test harness Test harness = program that feeds test inputs to a class

8 public static double power(int a, int n) { int r = 1; int b = a; int i = n ; while (i>0) { if (i%2 == 0) { b = b * b; i = i / 2;} else { r = r * b; i--; } } return r; }

9 Sources of Test Data Provided by humans Computer-generated sequence Random sequence

10 Test Cases Positive test case: expect positive outcome E.g square root of 100 Negative test case: expect negative outcome E.g square root of 100 Boundary test case: at boundary of domain Frequent cause for errors E.g square root of 0

11 Test Case Evaluation Manual Check property of result E.g. square root squared = original value Oracle = slower way of computing answer E.g. square root of x = x1/2

12 Regression Testing Save test cases Automate testing java Program test1.out java Program test2.out java Program test3.out Repeat test whenever program changes Test suite = collection of test cases Cycling = bug that is fixed but reappears in later versions Regression testing = testing against past failures

13 Test Coverage Black-box testing: test functionality without understanding internal structure White-box testing: take internal structure into account when designing tests Test coverage: the code that is actually executed during test cases Easy to overlook error branches during testing Make sure to execute each branch in at least one test case

14 Program Trace Output statements in your program for diagnostic purposes if (status == SINGLE) { System.out.println("status is SINGLE");... }

15 Stack Trace Stack trace tells you the contents of the call stack Throwable t = new Throwable(); t.printStackTrace(System.out); Looks like exception report: java.lang.Throwable at TaxReturn.getTax(TaxReturn.java:26) at TaxReturnTest.main(TaxReturnTest.java:30) Drawback of trace messages: Need to remove them when testing is complete, stick them back in when another error is found

16 Logging Get global logger object: Logger logger = Logger.getLogger("global"); Log a message logger.info("status is SINGLE"); By default, logged messages are printed. Turn them off with logger.setLevel(Level.OFF);

17 Assertions Assertion = assumption that you believe to be true assert y >= 0; root = Math.sqrt(y); If assertion fails, program is terminated Can be used to assert pre/postconditions Must compile/run with special flags javac -source 1.4 MyProg.java java -enableassertions MyProg


Download ppt "Testing & Debugging CSC 171 FALL 2004 LECTURE 13."

Similar presentations


Ads by Google