Skip to content

Instantly share code, notes, and snippets.

@meleyal
Last active December 16, 2015 07:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save meleyal/5398494 to your computer and use it in GitHub Desktop.
Save meleyal/5398494 to your computer and use it in GitHub Desktop.
Notes on testing
  • If you've already wrote the code, try commenting it all out, then start testing it piece by piece.

  • Test the public API (not internal/implementation details)

  • Test as little as possible to reach a given level of confidence

  • Test the critical parts of your application

  • Test expectations not implementations

  • Test complex logic

  • Function as a black box, test only the things you put in and get out

Knowing what not to test is the harder part of the lesson.

Factors:

  • Criticality
  • Likelihood of a mistake
  • Test things that will cost $ if they fail

Don't test first if you already know it

If I don’t typically make a kind of mistake, I don’t test for it.

Objects with complex logic (iterate, branch, queries) benefit greatly from testing. Especially testing first to nail down the object’s interface.


In the zone: permission not to test Out of the zone: go back and add tests

20% test-first, 80% test-after Code-to-test ratios above 1:2 is a smell More than 1/3 of your time - wrong

Test-first can slow you down if:

  • You see good design in your head.
  • You’re working on something new, then trying different things is a better way

Few applications are critical enough to warrant testing everything 99% of the apps don't need to test everything.

It is okay if Basecamp has bugs. 37s delegates its integration tests to its users, and that’s okay :) Have your users test all edge cases

A few high level integration tests can go a long way

Obvious bugs will get caught on internal beta testing

Have a script that a human goes through to verify important things Tell them, “try to break the website”.

Have good monitoring in place for when errors do pop up.

My gut feel is that non-trivial software is noticeably better (correct,stable) when coverage gets over 40%

Feel free to explore a few approaches before I settle on one.

Always test first when dealing with a bug. Write a test to capture the bug, then squash it.

More experience: less tests With experience: sometimes test first, test last, no test because it's trivial

Tests are harder to write last, so write them first.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment