I'm trying to test a function multiple times with different values using the testing module in Golang - does anyone know how to do this? I know how to do it with one value.
app.go
package main
func main () {
value := add(1, 2)
}
func add(a int, b int) int {
return a + b
}
but want to do something like:
app_test.go
package main
import (
"testing"
)
TestAdd1(t *test.T) {
res := add(1, 2)
if(res != 3) {
t.Error("Got: %d, want: %d", res, 3)
}
}
TestAdd2(t *test.T) {
res := add(2, 2)
if(res != 4) {
t.Error("Got: %d, want: %d", res, 4)
}
}