Sei sulla pagina 1di 12

Admin

DocTest

Black/White Box

UnitTest

Break

CSCA08 FALL 2014


W EEK 10 - T ESTING
Brian Harrington
University of Toronto Scarborough

November 10 - 14, 2014

Testing Methods

Break

Admin

DocTest

Black/White Box

UnitTest

Break

A DMIN S TUFF

A1
Some lessons learned?
Code Reviews
More interesting stuff to talk about this time
A2
Learn from your (or others) A1 mistakes...
Start early
Read thoroughly

Testing Methods

Break

Admin

DocTest

Black/White Box

UnitTest

Break

D OC T EST

Weve already been using this


Good for quick sanity checks
Tedious to do more than the basics
Somewhat difficult for sets/dictionaries
Example
Doesnt work at all for i/o
Really just testing outside" the code

Testing Methods

Break

Admin

DocTest

Black/White Box

UnitTest

Break

Testing Methods

B LACK B OX T ESTING

Imagine function as a black box


Cant see in/out
Can only see what goes in/what comes out
Try to cover all major test areas + boundary cases

Break

Admin

DocTest

Black/White Box

UnitTest

Break

Testing Methods

W HITE B OX T ESTING

Now we can see inside the box


Shouldnt it be clear box?
Can test for weaknesses specific to implementation details
More focused testing
When implementation details change, tests must change

also

Break

Admin

DocTest

Black/White Box

UnitTest

Break

Testing Methods

import unittest
import week10_functions as func
class TestCommonChar(unittest.TestCase):
def test_identical_single_char(self):
self.assertEqual(
func.common_chars(a, a),
(1,1),
"identical single char"
)
unittest.main(exit = False)
One class per function to test.
Function name must start with "test"
Expected return value
Message for when error occurs

Break

Admin

B REAK

DocTest

Black/White Box

UnitTest

Break

Testing Methods

Break

Admin

DocTest

Black/White Box

UnitTest

Break

Testing Methods

C OVERAGE T ESTING

Try to cover all possible scenarios


Exhaustive testing too tedious/difficult
Break up test-space into areas
Pick representative examples from each area
Pick examples from boundaries between areas

Break

Admin

DocTest

Black/White Box

UnitTest

Break

Testing Methods

A DVERSARIAL T ESTING

Try to break your (or preferably someone elses code)


Usually white box
Often monetary incentives
Motivated to find bugs

Break

Admin

DocTest

Black/White Box

UnitTest

Break

Testing Methods

R EGRESSION T ESTING

When you make a change, check that you havent

introduced a bug to other code


Built new test cases on top of old, run everything
Costly, but effective
Individual cases can be derived through other methods

Break

Admin

B REAK

DocTest

Black/White Box

UnitTest

Break

Testing Methods

Break

Admin

DocTest

Black/White Box

UnitTest

Break

Testing Methods

T ESTING L EVELS

Unit - Test individual components


Integration - Putting components together
System - System as a whole
Acceptance - Testing with users
Release - Testing in the real world
alpha (select group, expecting buggy code
beta (larger group, expect mostly working code)
full-release (it better be working by this point)
As we move ahead 1 level, difficulty/cost of repairing a

logic error multiplies by ~10x

Break

Potrebbero piacerti anche