Testing - PowerPoint PPT Presentation

About This Presentation
Title:

Testing

Description:

Negative test case: expect negative outcome. E.g ... take internal structure into account when designing tests ... error branches during testing ... – PowerPoint PPT presentation

Number of Views:24
Avg rating:3.0/5.0
Slides: 18
Provided by: thaddeusf
Category:
Tags: testing

less

Transcript and Presenter's Notes

Title: Testing


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 (igt0)
  • if (i2 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 lt test1.in gt
    test1.outjava Program lt test2.in gt
    test2.outjava Program lt test3.in gt 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 reportjava.lang.Throwable
    at TaxReturn.getTax(TaxReturn.java26) at
    TaxReturnTest.main(TaxReturnTest.java30)
  • 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 objectLogger 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 gt 0root 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
Write a Comment
User Comments (0)
About PowerShow.com