go-by-test/hello_test.go

31 lines
613 B
Go

package main
import "testing"
func TestHello(t *testing.T) {
t.Run("Hello someone", func(t *testing.T) {
got := Hello("Jason", "English")
exp := "Hello Jason"
assertCorrectMsg(t, got, exp)
})
t.Run("Hello default", func(t *testing.T) {
got := Hello("", "English")
exp := "Hello world"
assertCorrectMsg(t, got, exp)
})
t.Run("Hello default", func(t *testing.T) {
got := Hello("Elodie", "Spanish")
exp := "Hola Elodie"
assertCorrectMsg(t, got, exp)
})
}
func assertCorrectMsg(t testing.TB, got, exp string) {
t.Helper()
if got != exp {
t.Errorf("got %q expected %q", got, exp)
}
}