hellofresh / go-readinglist

Useful links for golang
MIT License
33 stars 6 forks source link

Best practices for Testing #6

Open trustmaster opened 7 years ago

trustmaster commented 7 years ago

I would like to open a discussion on recommended approaches to testing Golang projects at HelloFresh, split into sections below.

Testing framework

I've noticed the following testing combinations in some of the existing Go projects at HelloFresh:

  1. No tests

:trollface:

  1. testing + testify

Some classic tests with assertion.

  1. GoDog + plain testing + testify

I suppose this was supposed to be somewhat BDD, with some traditional unit tests and testify for assertions. But I haven't understood how the responsibilities between godog-generated tests and other test files are separated in that project.

Could someone shed more light on the subject and also why you prefer Godog over Ginkgo and GoConvey?

Mocks

Do you prefer mocking external services at interface level or via HTTP mocks? What do you use for that?

HTTP requests

Do you use any specific approach to tests HTTP route handlers?


If you have more feedback to share, go ahead. I'll combine it into a wiki page later on.

trustmaster commented 7 years ago

After studying the existing repos in the company, I'm gonna answer myself with what I found as the most common or most trending pattern:

Functional tests

High-level functional tests are using Godog.

Unit tests

Lower level code is covered with traditional unit tests using testing and testify.assert

HTTP requests

net/http/httptest