gotestsum
gotestsum copied to clipboard
Display build/setup failures output
gotestsum is hiding the output when the test code cannot be built, which can make debugging harder. For example:
package main
import (
"fmt"
"testing"
"github.com/stretchr/testify/require"
)
//go:embed toto.txt
var toto string
func TestHello(t *testing.T) {
fmt.Println("Hello, World!")
require.True(t, true)
}
Cannot be built because embed is not imported properly. If you try to run that test with go test -v you will get:
# testgo [testgo.test]
./main_test.go:10:3: go:embed only allowed in Go files that import "embed"
FAIL testgo [build failed]
with gotestsum --format standard-verbose:
FAIL testgo [build failed]
=== Failed
=== FAIL: . (0.00s)
FAIL testgo [build failed]
DONE 0 tests, 1 failure in 0.348s
Which is hard to debug. Would be nice to have a flag that allows us to have build error displayed, and not only [build failed]
This is what I see when I try that with the latest release of gotestsum, using go1.24.1.
All of these report the error properly for me. Are you using an older version of Go, or an older version of gotestsum? I can't reproduce the issue.
$ gotestsum ./tmp2
✖ tmp2
=== Failed
=== FAIL: tmp2 (0.00s)
FAIL gotest.tools/gotestsum/tmp2 [build failed]
=== Errors
tmp2/main_test.go:8:3: go:embed only allowed in Go files that import "embed"
DONE 0 tests, 1 failure, 1 error in 0.000s
$ gotestsum -f testname ./tmp2
FAIL tmp2
=== Failed
=== FAIL: tmp2 (0.00s)
FAIL gotest.tools/gotestsum/tmp2 [build failed]
=== Errors
tmp2/main_test.go:8:3: go:embed only allowed in Go files that import "embed"
DONE 0 tests, 1 failure, 1 error in 0.000s
$ gotestsum -f standard-verbose ./tmp2
FAIL gotest.tools/gotestsum/tmp2 [build failed]
=== Failed
=== FAIL: tmp2 (0.00s)
FAIL gotest.tools/gotestsum/tmp2 [build failed]
=== Errors
tmp2/main_test.go:8:3: go:embed only allowed in Go files that import "embed"
DONE 0 tests, 1 failure, 1 error in 0.000s