Skip to content

Instantly share code, notes, and snippets.

@winnab
Created August 29, 2017 06:58
Show Gist options
  • Save winnab/085d2adfb8d7b0405757d04d50e97dfb to your computer and use it in GitHub Desktop.
Save winnab/085d2adfb8d7b0405757d04d50e97dfb to your computer and use it in GitHub Desktop.
ODB style guide

Reference

Tests - Ginkgo Proverbs

Local Immutable Test Setup

  • Define test setup, such as CF and BOSH APIs, or mock service adapters as close to the test as possible
  • Don't modify a generic test setup for each context, create a new one
  • Consider fluent builders to make this clear, without requiring excessive code
  • Strongly consider any requirement to set up in BeforeSuite
  • Avoids mutation leaks by avoiding shared variables between tests

Avoid JustBeforeEach, reduce BeforeEach

  • Locally defined setup for each test removes the need to run JustBeforeEach after some local BeforeEach
  • The "Act" from Arrange, Act, Assert should happen close to, or in, the It() not in a global JustBeforeEach

Don't strive for the most granular tests

  • When testing long running actions, combine related assertions in a single It(), BeforeEach is no longer required
  • Cost of repeatedly running long running actions to assert on related responses is high

Don't re-invent Gomega

  • Use the most appropriate matcher for the situation
  • For example, SatisfyAll() will match a number of related assertions
  • Spend time when writing tests to select the most appropriate tool

Don't repeat Ginkgo

  • Use the most appropriate Ginkgo tool
  • Consider if multiple contexts testing a similar action could be a table test

Describe behaviour

  • Avoid implementation details in Context and It descriptions
  • Use ‘responds with...’ to describe HTTP responses, instead of ‘returns...’

Code

Split large packages

  • The broker package is large and growing, what can be extracted?
  • Split long files when they grow unwieldy.

Error handling

  • Avoid coupling to another package by using its error types. Create an interface that describes the error's behaviour and assert the interface. Dave Cheney gives an example of how to avoid such 'Sentinel' errors.
@sf105
Copy link

sf105 commented Aug 29, 2017

Not bad. Can we publish these?

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