Unit Testing Venkat Subramaniam svenkat@cs.uh.edu 1 Unit Testing - - PDF document

unit testing
SMART_READER_LITE
LIVE PREVIEW

Unit Testing Venkat Subramaniam svenkat@cs.uh.edu 1 Unit Testing - - PDF document

Unit Testing Venkat Subramaniam svenkat@cs.uh.edu 1 Unit Testing Venkats rant on Unit Testing What is it? Benefits Rubys emphasis on it Venkat Subramaniam svenkat@cs.uh.edu 2 Your Test Your Test inherits


slide-1
SLIDE 1

1

Venkat Subramaniam – svenkat@cs.uh.edu

Unit Testing

2

Venkat Subramaniam – svenkat@cs.uh.edu

Unit Testing

  • Venkat’s rant on Unit Testing

– What is it? – Benefits – Ruby’s emphasis on it

slide-2
SLIDE 2

3

Venkat Subramaniam – svenkat@cs.uh.edu

Your Test

  • Your Test inherits from

Test: : Unit: : TestCase

– require ‘test/ unit’

  • Use assert methods like assert_equals
  • Test methods start with test prefix
  • setup and teardown methods

4

Venkat Subramaniam – svenkat@cs.uh.edu

Running Tests

  • ruby testfilename.rb
  • ruby testfilename.rb –name test_name
slide-3
SLIDE 3

5

Venkat Subramaniam – svenkat@cs.uh.edu

Asserts

  • assert
  • assert_nil
  • assert_not_nil
  • assert_equal
  • assert_not_equal
  • assert_in_delta
  • assert_raise
  • assert_nothing_raised
  • assert_instance_of
  • assert_kind_of
  • assert_respond_to
  • assert_match
  • assert_no_match
  • assert_same
  • assert_not_same
  • assert_operator
  • assert_throws
  • assert_send
  • flunk

6

Venkat Subramaniam – svenkat@cs.uh.edu

Unit Tests

slide-4
SLIDE 4

7

Venkat Subramaniam – svenkat@cs.uh.edu

Organizing Your Tests

  • Put your tests in a test directory parallel to the

code directory

  • To run your tests from different directories you

need to help ruby located it

  • The above modified $: (variable that represents

load path) so that it gets the ../ src directory relative to where the test is

8

Venkat Subramaniam – svenkat@cs.uh.edu

The $: magic

slide-5
SLIDE 5

9

Venkat Subramaniam – svenkat@cs.uh.edu

Organizaing your tests