Library https://github.com/stretchr/testify.
It will add a depedency, but thats worth it.
- Much less bloated and much more readable tests and, hence high maintainability
- Standard in golang libraries
- Automatic diff formatting
Example
func TestFilterLine_FiltersEachLineThroughSuppliedFunction(t *testing.T) {
t.Parallel()
input := "hello\nworld"
want := "HELLO\nWORLD\n"
got, err := script.Echo(input).FilterLine(strings.ToUpper).String()
if err != nil {
t.Fatal(err)
}
if want != got {
t.Error(cmp.Diff(want, got))
}
}
becomes
func TestFilterLine_FiltersEachLineThroughSuppliedFunction(t *testing.T) {
t.Parallel()
input := "hello\nworld"
want := "HELLO\nWORLD\n"
got, err := script.Echo(input).FilterLine(strings.ToUpper).String()
require.NoError(t, err)
assert.Equal(t, want, got)
}
@bitfield Let me know what you think about this.
Library https://github.com/stretchr/testify.
It will add a depedency, but thats worth it.
Example
becomes
@bitfield Let me know what you think about this.