Skip to content

Latest commit

 

History

History
50 lines (27 loc) · 1.34 KB

2017-wathan-mocking.markdown

File metadata and controls

50 lines (27 loc) · 1.34 KB

Alternative Facts You've Been Told About Testing

Adam Wathan, Laracon Online 2017

  • "Almost all of your tests should be unit tests."
  • "Your tests should never touch the database."
  • "If you can't test your code in isolation, it's poorly designed."

Are these true?

An Example... (according to the lies you might have been told)

[Products Controller with injected dependencies, using CommandBus, Repository]

[A look at the test for ProductsController, completely using mocks]

How Did We Do? (Measuring up to 'best practices')

We passed all the alternative fact tests. :) But something isn't right.

And the alternative fact folks would say "YOU'RE STILL DOING IT WRONG!"

Let's Take Another Look...

TDD is all about the red-green refactoring loop.

  • Write a failing test
  • Get it to pass
  • Refactor at will

If refactoring is a fundamental part of TDD, and isolated testing gets in the way of refactoring, then isolated unit testing is incompatible with TDD.

Diagram Time

[Layout of program process and test]

Let's Try This...

"Isolated Tests are a Scam." - Adam Wathan, 2017

What About External Services?

How do you test making payments with Stripe, for example?

Don't Worry About Isolation

Instead, introduce boundaries when they solve a real problem.