Table Test
Contoh code
package main
import (
"fmt"
)
func main() {
result := SayHi("Utsman")
fmt.Println(result)
}
func SayHi(name string) string {
return name
}
package main
import (
"testing"
)
type TestTable struct {
input string
expected bool
subtestName string
errorMessage string
}
func TestSayHi2(t *testing.T) {
var tableTest []TestTable = []TestTable{
{
input: "Andi",
expected: true,
subtestName: "Test-1",
errorMessage: "Is Andi",
},
{
input: "Umar",
expected: false,
subtestName: "Test-2",
errorMessage: "Is Not Andi",
},
{
input: "Utsman",
expected: false,
subtestName: "Test-3",
errorMessage: "Is Not Andi",
},
}
for _, v := range tableTest {
t.Run(v.subtestName, func(t *testing.T) {
if result := SayHi(v.input); result != "Andi" {
t.Error("Not Andi")
}
})
}
}Last updated