Extract a custom assertion
This commit is contained in:
parent
0f3e93e7d5
commit
d4bc9ae15f
|
@ -3,21 +3,25 @@ package main
|
||||||
import "testing"
|
import "testing"
|
||||||
|
|
||||||
func TestHello(t *testing.T) {
|
func TestHello(t *testing.T) {
|
||||||
t.Run("saying hello to people", func (t *testing.T) {
|
assertCorrectMessage := func(t testing.TB, got string, want string) {
|
||||||
got := Hello("Oliver")
|
t.Helper()
|
||||||
want := "Hello, Oliver"
|
|
||||||
|
|
||||||
if got != want {
|
if got != want {
|
||||||
t.Errorf("got %q want %q", got, want)
|
t.Errorf("got %q want %q", got, want)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
t.Run("saying hello to people", func (t *testing.T) {
|
||||||
|
got := Hello("Oliver")
|
||||||
|
want := "Hello, Oliver"
|
||||||
|
|
||||||
|
assertCorrectMessage(t, got, want)
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("say 'Hello, World' when an empty string is supplied", func (t *testing.T) {
|
t.Run("say 'Hello, World' when an empty string is supplied", func (t *testing.T) {
|
||||||
got := Hello("")
|
got := Hello("")
|
||||||
want := "Hello, World"
|
want := "Hello, World"
|
||||||
|
|
||||||
if got != want {
|
assertCorrectMessage(t, got, want)
|
||||||
t.Errorf("got %q want %q", got, want)
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue