Skip to content

Instantly share code, notes, and snippets.

@pricees
Last active August 29, 2015 14:17
Show Gist options
  • Select an option

  • Save pricees/46cf6fec5adb69fae9ee to your computer and use it in GitHub Desktop.

Select an option

Save pricees/46cf6fec5adb69fae9ee to your computer and use it in GitHub Desktop.
Test Talk for DBCx

The Plan

  • The Analogy
  • Testing
  • Testing Do's
  • Testing Don'ts
  • Summary

Emotions Driven Testing

  • a.k.a. CYA testing
  • Testing the framework, core, standard libraries?
  • Testing across boundaries?

Separate Business Logic from Models

  • Beware of binding logic to the ORM methods
  • Use abstractions wisely

Testing Do's

  • Do remember separation of concerns, "It's Not My Business")
  • Test the public interface
  • Test behavior
  • Stub and mock to isolate SUT
  • Do watch out for smells
  • Use factories
  • Test edge cases, integration points
  • Use memory, rather than persistent models
  • Remember the Law of Demeter

Testing Don'ts

  • Cross Boundaries
  • Don't test the framework (e.g. associations, simple scopes)
  • Don't get emotional about testing
  • Don't test privates
  • Mock everything (it's not the hammer)
  • Test edge cases with integration tests

The Analogy [TheAnalogy]

Background:
It's tax season and I had to overnight my all my W-2s and whatnot to my tax guy in California and he had to overnight all the finished tax forms back to me, to sign, and send to that wonderful agency known as the Internal Revenue Service.

So lets discuss the curious path of this request.

The Envelope

  • Sender address follows standard format
    • Return to sender
  • Receiver address follows standard format
    • Can't find address
    • Return to sender
  • Stamp? Stamp previously used on other envelope?
  • Letter too heavy?

Mailbox

  • USPS already picked up mail?
  • Mail damaged?
  • Am I using USPS, FedEx, UPS?

Onto the Post Office

  • Do I want tracking?
  • Do I want insurance?
  • Do I require a signature?
  • What are the contents? (Are the allowed?)

Routing (In)

  • Goes to Chicago, IL sorting center →
  • Leave's distribution center →
  • Arrive's in receivers distribution center →
  • Moved to Whittier, CA post office sorting center →
  • Out for delivery
  • Address found? If not, return to send

Mike's Receive's Envelope

  • Is content's correct, according to the manifest
  • Are the content's filled out correctly?
  • Does Mike have all the information he needs?

Mike's Work Load (ETL Job)

  • Did I include personal check? If not, light contents on fire.
  • Extracts facts from my documents
  • Translates facts into a story that maximizes my returns
  • Loads values into government forms
  • Prints out new documents
  • Stuffs into envelope for pickup from office

Routing (Out)

  • Goes to Whitter, CA sorting center →
  • Leave's distribution center →
  • Arrive's in receivers distribution center →
  • Moved to Chicago, IL post office sorting center →
  • Out for delivery
  • Address found? If not, return to sender

Mike gets sick

  • Service Unavailable (503)

Things I would never ask the Postal Worker

  • Is this Mike the CPA's correct address?
  • Do my taxes look like they are filled out correctly?
  • What's my address?
  • How do you plan to deliver the mail, which route?
  • Can you please mail this without a stamp?
  • Can you just mail this UPS box? You are headed that way anyway
  • The envelope from Mike, so.... whats in here?
  • Mind if I wait in your sorting center until the letter from Mike comes?

Things Mike would never ask the delivery person

  • Did Ted include a check?
  • Did this include Ted's W-2s?
  • How much lying did he do?
  • Is this Ted's real address?

Things the post office would never ask

  • Did you give Mike everything he wants?
  • Did you provide Ted with self-address stamped envelopes to the IRS?

What do these have in common

  • Separation of concerns
  • "It's Not My Business"

Let's Abstract this Process

  • Show models, collaborators, components
  • Interaction
  • Business logic

Tests Ahoy!

Okay, I am satisfied that it works in isolated parts

  • Integrate
  • Not too much
  • Not to little
  • Test points of integration
  • Test points of integration in isolated business units
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment