Marco
Marco

Reputation: 607

Intercepting test failures to provide additional context

TL;DR: Is there any known hack to capture and/or print additional context when a Golang test fails? (using standard library testing)

Example:

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.

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.

Upvotes: 0

Views: 46

Answers (0)

Related Questions