More Unit Tests - PowerPoint PPT Presentation

1 / 8
About This Presentation
Title:

More Unit Tests

Description:

CONDITION: may be any perl expression. STRING: test name (i.e. ... How can we tell what is going on without output/debugger? ( aka, why is my test failing) ... – PowerPoint PPT presentation

Number of Views:31
Avg rating:3.0/5.0
Slides: 9
Provided by: csr8
Category:
Tags: debugger | more | tests | unit

less

Transcript and Presenter's Notes

Title: More Unit Tests


1
More Unit Tests
  • October 20th, 2004
  • Advising Fair Link
  • Date Tuesday, October 26th
  • Time 4-5pm
  • Where Union 3202

2
TestSimple
  • perldoc TestSimple
  • ok(CONDITION, STRING)
  • CONDITION may be any perl expression
  • STRING test name (i.e. connected test)
  • ALL tests done in SCALAR context!
  • ok(_at_my_array, array test)
  • Only tests if _at_my_array is empty

3
Example ok()
  • my _at_links qw(1, 2, 3, 4)
  • my r Router-gtnew(r, 1, 2, 10, \_at_links)
  • ok(defined(r), Router defined)
  • ok(ref r eq Router, Router isa Router)
  • ok(r-gtname() eq r, name() works)
  • dk(r-gtname(r1) eq r1, name(scalar) works)

4
TestMore
  • Has more tests
  • require_ok(COND, STRING)
  • stop testing this module if not ok
  • Other forms of ok()
  • is(this, that, STRING)
  • isnt(this, that,STRING)
  • Mnemonic this is ok, this isnt ok
  • Better output if test fails!

5
TestMore
  • Warning
  • is(r-gtisa(Router), 1, isa test)
  • Checks return of isa only!
  • Use ok() for true/false testing
  • Unit test isa_ok(ref, TYPE)
  • isa_ok(r, Router)
  • isa_ok(array, ARRAY)

6
Diagnostics
  • How can we tell what is going on without
    output/debugger? (aka, why is my test failing)
  • Diag(_at_MESSAGE)
  • Ok(this, test) or diag (Tested, this,
    expected, that)
  • Mnemonic open or die ? ok or die

7
Array/Hash Testing
  • is_deeply(this, that, test_name)
  • Compares each element of array/hash with is()
  • this, that must be references

8
Array/Hash Testing
  • eq_hash(\h1, h2, testname)
  • Compares key, values of each hash
  • eq_array(\_at_a1, \_at_a2, testname)
  • Compares each array element
  • Handles muli-level structures
Write a Comment
User Comments (0)
About PowerShow.com