From b3dfaa908668cfd061ccf02d96167ef19a2d5328 Mon Sep 17 00:00:00 2001 From: Eyal Date: Sun, 9 Jul 2017 14:22:15 +0300 Subject: [PATCH] fail: add test name for logged output In case of a test failure, the test name will be logged to the output with makes debugging easier, specially in case of table driven tests. --- assert/assertions.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/assert/assertions.go b/assert/assertions.go index 3f1f6f7..522017c 100644 --- a/assert/assertions.go +++ b/assert/assertions.go @@ -231,6 +231,13 @@ func Fail(t TestingT, failureMessage string, msgAndArgs ...interface{}) bool { {"Error", failureMessage}, } + // Add test name if the Go version supports it + if n, ok := t.(interface { + Name() string + }); ok { + content = append(content, labeledContent{"Test", n.Name()}) + } + message := messageFromMsgAndArgs(msgAndArgs...) if len(message) > 0 { content = append(content, labeledContent{"Messages", message})