Skip to content

Instantly share code, notes, and snippets.

@fr33m0nk
Forked from meerasndr/go-with-tests.md
Created January 10, 2024 18:35
Show Gist options
  • Save fr33m0nk/d42f10c1ba6bbb78a528b165863cd7df to your computer and use it in GitHub Desktop.
Save fr33m0nk/d42f10c1ba6bbb78a528b165863cd7df to your computer and use it in GitHub Desktop.
Notes from Go with Tests
  • Write the test first -> Try and run the test -> Write the minimal amount of code for the test to run and check the failing test output -> Write enough code to make it pass -> Refactor
  • We must not neglect our test code in the refactoring stage
  • It is important to question the value of your tests. It should not be a goal to have as many tests as possible, but rather to have as much confidence as possible in your code base. Having too many tests can turn in to a real problem and it just adds more overhead in maintenance. Every test has a cost.
  • reflect.DeepEqual - useful for seeing if any two variables are the same. Caveat: It is not type safe. Compiles even if silly comparisons like array == string is done. https://golang.org/pkg/reflect/#DeepEqual
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment