Skip to content

Use testify package for unit tests #237

@lazysegtree

Description

@lazysegtree

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions