TL;DR: Is there any known hack to capture and/or print additional context when a Golang test fails? (using standard library testing
)
Example:
<code>func TestSomething(t *testing.T) {
...
...
if ... {
t.Fatalf("Something went wrong!")
}
</code>
<code>func TestSomething(t *testing.T) {
...
...
if ... {
t.Fatalf("Something went wrong!")
}
</code>
func TestSomething(t *testing.T) {
...
...
if ... {
t.Fatalf("Something went wrong!")
}
I would like to attach some generic function to be invoked before the test returns, e.g. debug.PrintStack()
I am working on a large codebase with hundreds of tests.
- Moving to a different testing library is not an option
- Modifying each test is not an option (e.g. add
defer
) - I’d really like to avoid re-implementing
go test
logic… - (the actual use case is not
debug.PrintStack()
— I want to notify some other system of the test failure)
I can see from testing
documentation and code that this is not supported.
However I also know if one is determined enough, this is possible, and I am hoping someone can point to some clever hack I can take inspiration from.