iver-wharf / iver-wharf.github.io

Documentation of Wharf
https://iver-wharf.github.io
MIT License
2 stars 0 forks source link

Document unit-test naming convention #64

Open applejag opened 3 years ago

applejag commented 3 years ago

Our unit tests are not that coherent in their names. We use a mix of different naming conventions, as they are written by different developers.

The simple answer is just to name them:

func Test{NameOfTypeOrFunction}(t *testing.T)

// Example
func Add(a, b int) int

func TestAdd(t *testing.T)

But it gets diffuse when we start having multiple tests targetting the same function/type/method but with slight variations.

An example format of this (though not that great IMO):

func Test{NameOfTypeOrFunction}_{StateOfType}_{ExpectedResult}(t *testing.T)
func TestAdd_GivenNegativeValues_ReturnsNegative(t *testing.T)

Suggest to write an RFC of this.