avoid t.Fatal() in tests (#9189)
I've been burned a few times by tests that simply fatal, requiring me to run another build to learn more about what the mismatch was. Avoid this. This is part of a long running goal of mine to make testing "better".
Этот коммит содержится в:
коммит произвёл
Jesús Espino
родитель
0bbabd137b
Коммит
d8c8a19d35
@@ -6,6 +6,8 @@ package model
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestClusterMessage(t *testing.T) {
|
||||
@@ -17,9 +19,7 @@ func TestClusterMessage(t *testing.T) {
|
||||
json := m.ToJson()
|
||||
result := ClusterMessageFromJson(strings.NewReader(json))
|
||||
|
||||
if result.Data != "hello" {
|
||||
t.Fatal()
|
||||
}
|
||||
require.Equal(t, "hello", result.Data)
|
||||
|
||||
badresult := ClusterMessageFromJson(strings.NewReader("junk"))
|
||||
if badresult != nil {
|
||||
|
||||
Ссылка в новой задаче
Block a user