1 / 17

Testing & Debugging

Testing & Debugging. CSC 171 FALL 2004 LECTURE 13. Reading. Read Chapter 8 of Horstmann We will be doing this in labs. BUGS?. TERMINOLOGY. Using the term “fault” instead of “bug” is one step toward professionalism. Therac-25. PATRIOT MISSILE.

mschramm
Download Presentation

Testing & Debugging

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

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 outcomeE.g square root of 100 • Negative test case: expect negative outcomeE.g square root of 100 • Boundary test case: at boundary of domainFrequent cause for errorsE.g square root of 0

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

  12. Regression Testing • Save test cases • Automate testingjava Program < test1.in > test1.outjava Program < test2.in > test2.outjava Program < test3.in > 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 purposesif (status == SINGLE) { System.out.println("status is SINGLE"); ... }

  15. Stack Trace • Stack trace tells you the contents of the call stackThrowable 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 messagelogger.info("status is SINGLE"); • By default, logged messages are printed. Turn them off withlogger.setLevel(Level.OFF);

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

More Related