Skip to content

Instantly share code, notes, and snippets.

@leodutra
Created August 9, 2018 09:42
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 leodutra/0634f303a3e765e96bf4100ec03398b2 to your computer and use it in GitHub Desktop.
Save leodutra/0634f303a3e765e96bf4100ec03398b2 to your computer and use it in GitHub Desktop.
Unit testing mindset

On UNIT TESTING I'd recommend/remind (some of them may have exceptions when testing non-TDD legacy):

  • given/when/then or arrange/act/assert structuring;
  • use before each/ after each for setting up common resources;
  • one assert per test method (or at least minimal, keeping it sane);
  • avoid test interdependence;
  • keep tests plan, free of if/ while/ for/ case and shared methods/ functions. Create methods for different conditions;
  • duplicated code is better than shared functions/methods;
  • do unit test behavior (input and output). Don't go spying on internal variables and dependencies as this may change and break tests, even when the inputs and outcomes are in compliance with the specification. (Ex: if you spy a call on a dependency of toBase64... and the dependency is not used anymore, test will break even if the input and output are right);
  • exceptions are exceptions, we can't do much on legacy built without TDD in mind.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment