Last active
June 20, 2018 10:47
-
-
Save dmotylev/3e1fa955fba45a9aa8c44e47296bf821 to your computer and use it in GitHub Desktop.
Go's test func template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func TestType_TestFunc(t *testing.T) { | |
tests := []struct { | |
name string | |
wantErr bool | |
}{ | |
{"test", false}, | |
} | |
const wantTest = -1 | |
for testNo, test := range tests { | |
//noinspection GoBoolExpressions | |
if wantTest > -1 && wantTest != testNo { | |
continue | |
} | |
t.Run(fmt.Sprintf("%d_%s", testNo, test.name), func(t *testing.T) { | |
var err error | |
// err := TestFunc() | |
if test.wantErr != (err != nil) { | |
t.Errorf("TestFunc() err=%v, wantErr=%t", err, test.wantErr) | |
} | |
}) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment