-
-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: runner go test name #64
base: main
Are you sure you want to change the base?
Conversation
…the golang test table
@maxwelbm sounds good. would you please showing a go example file for testing? |
an example of the test table that is the golang test pattern |
Can i participate in this project too ? |
Yes, of course :) |
@maxwelbm I have issue with this PR, since I just fully investigated how sub tests work.
My test Go codes: func testFunc(a int) int {
return a + 1
} func TestTable(t *testing.T) {
testCases := []struct {
a int
want int
}{
{1, 2},
{2, 3},
{3, 4},
{4, 6},
}
for _, tc := range testCases {
t.Run(fmt.Sprintf("%d in %d", tc.a, tc.want), func(t *testing.T) {
if testFunc(tc.a) != tc.want {
t.Errorf("%d not in %d", tc.a, tc.want)
}
})
}
} |
@crispgm in the example you presented it is not possible to apply, but this test table model without the name is not used, because in this case it only runs the entire block of tests func TestTable(t *testing.T) {
testCases := []struct {
name string
a int
want int
}{
// go test -run TestTable/case_01
{name: "case 01", 1, 2}, // execute this isolated block
{2, 3},
{3, 4},
{4, 6},
}
for _, tc := range testCases {
t.Run(fmt.Sprintf("%d in %d", tc.a, tc.want), func(t *testing.T) {
if testFunc(tc.a) != tc.want {
t.Errorf("%d not in %d", tc.a, tc.want)
}
})
}
} Answers |
Hello, I felt the need to run isolated tests and added a new command
GoTestName
to improve the work with testsExample
case I want to run in the table testing model
name: "Lorem ipsum dolor sit amet, consectetur"
go test -run TestExample/Lorem_ipsum_dolor_sit_amet,_consectetur_adipiscing_elit