Testing Why bother? Professor Larry Heimann Carnegie Mellon - - PowerPoint PPT Presentation

testing why bother
SMART_READER_LITE
LIVE PREVIEW

Testing Why bother? Professor Larry Heimann Carnegie Mellon - - PowerPoint PPT Presentation

Testing Why bother? Professor Larry Heimann Carnegie Mellon University Information Systems Program Why do testing? Comic of the Day... Class example: romanic_testing Get the code at https://github.com/profh/romanic_testing Unit testing


slide-1
SLIDE 1

Testing — Why bother?

Professor Larry Heimann Carnegie Mellon University Information Systems Program

slide-2
SLIDE 2

Why do testing?

slide-3
SLIDE 3
slide-4
SLIDE 4
slide-5
SLIDE 5

Comic of the Day...

slide-6
SLIDE 6

Class example: romanic_testing

Get the code at https://github.com/profh/romanic_testing

slide-7
SLIDE 7

Unit testing assertions

  • assert(actual, message) # Asserts truth
  • assert_equal(expected, actual, message)
  • assert_in_delta(expected_float, actual_float, delta, message)
  • assert_match(pattern, string, message)
  • assert_nil(object, message) / assert_not_nil
  • assert_raise(Exception, ..., message) { block ... }
  • assert_difference(expressions, difference = 1, &block)
slide-8
SLIDE 8

ActiveSupport::TestCase

  • By default, Rails uses ActiveSupport::TestCase to handle unit testing.
  • Rails ships with three types of tests: unit (models), functional (controllers), and

integration (full MVC stack).

  • Every method in the test case with a name that starts with test_ represents

a single test that gets executed by the framework

  • Before every test method the setup method is invoked, and afterwards the

teardown method

  • Every test method makes one or more assertions about the behavior of the

class under test

slide-9
SLIDE 9

More on unit testing

  • Unit testing is done on models only
  • All models have a default test created upon rails generate model or

rails generate scaffold

  • Unit tests are stored in the directory test/models within a Rails project
  • Tests can be executed using rake test:units or rake test or by

executing a particular file (e.g., ruby test/unit/owner_test.rb)

  • Can measure test coverage with gems like simple_cov (what we will use in

grading phases). These coverage tools are not perfect and especially vulnerable to false positive readings (i.e., says you have full coverage when you do not). No substitute for your own testing analysis.

slide-10
SLIDE 10

Looking at basic unit tests in PATS

Get the code at https://github.com/profh/PATS_67272

slide-11
SLIDE 11

pItlh