CSCE 315 Lecture 20

From Notes
Jump to navigation Jump to search

« previous | Wednesday, March 7, 2012 | next »


Testing

if (cond1) {
    x = a;
} else {
    x = b;
}

if (cond2) {
    y = x+1;
} else {
    y = x+2;
}

if (cond3) {
    z = c;
} else {
    z = d;
}
  • Logic Coverage would have 8 conditions (TTT, TTF, TFT, TFF, FTT, FTF, FFT, FFF)
  • Data flow would have 4 (all defined-used paths: (TTT, TFF, FT?, FF?)
  • Structured Basis would have 2 (TTT, FFF)


Test case design

If you don't know the code,

  • Boundary analysis still applies
  • Equivalence partitioning (don't create tests that do the same things
  • Bad data (too much/little data, wrong kind, uninitialized data)
  • Good data (min/max/middle, backward compatability)

Test Automation

Running tests by hand is not appropriate Should do a lot of tests

Regression Testing

Find anything that has been broken by "fixing" something else Save old test cases.

Stup Routines

  • Return standard data
  • Burn cycles to simulate a long computation
  • etc.

Test Harness

Calls the routine being tested:

  • fixed input
  • interactive input
  • file-based input
  • command-line argument input

Data Generators

Make a lot of data automatically (a lot more than by hand)

System Perturbers

  • Reinitialize memory to something other than 0 to fix uninitialized variable errors.
  • Rearrange memory locations to find out-of-bounds errors
  • Memory bounds checking
  • System failure simulation

Mock Objects

Setting up a dummy service.


Test-Driven Development

  1. Write test
  2. Run test (should fail)
  3. Write code
  4. Run Test (should pass)
  5. Refactor
  6. Run test (should still pass)
  7. Repeat

Refactoring

  • Clean up your code.
  • Having a test suite can make sure that refactoring won't break your code.

Common Operations

  • Extract Class
  • Extract Interface
  • Extract Method
  • Replace type with subclasses
  • replace conditional with polymorphic objects
  • Form template
  • Introduce "explaining" variable
  • Replace constructor with "factory" method
  • Replace inheritance with delegation
  • Replace magic number with symbolic constant
  • Replace nested conditional with guard clause.