Skip to content

Instantly share code, notes, and snippets.

@nikku
Last active October 30, 2016 13:48
Show Gist options
  • Save nikku/1dc2edb553565238c7bf to your computer and use it in GitHub Desktop.
Save nikku/1dc2edb553565238c7bf to your computer and use it in GitHub Desktop.
Good unit / integration tests. A template.

Good Unit Tests

... are structured into given, when and then.

given

What do I actually assume to be already working / what needs to be set up?

when

Time to execute something!

then

Assert that stuff you executed actually works as expected.

FAQ

I have multiple when / then blocks!

You are probably doing it wrong. Tests should be concise, self contained and focused.

Try to write multiple test cases for each when/then block.

I cannot get this structure running in JavaScript

What about using something like this as your test template?

// given
var x = 10;

// when
var y = 10 + x;

// then
expect(y).to.eql(20);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment