I have a go test called Closingtimeisshowncorrectlywhenit'sonthenextday (it's a…
- User
I have a go test called Closing_time_is_shown_correctly_when_it's_on_the_next_day
(it's a subtest): name: "Closing time is shown correctly when it's on the next day",
Give me a go test -run command to run only this test
- Assistant
To run a specific subtest in Go using
go test -run, you need to specify the top-level test name followed by the subtest name, separated by a slash/.Assuming your top-level test function (in
*_test.go) is something like:gofunc TestSomething(t *testing.T) { t.Run("Closing time is shown correctly when it's on the next day", func(t *testing.T) { // subtest code }) } - User
The hierarchy is this:
func TestGetDeliveryHours(t *testing.T) { t.Run("Returns correctly formatted delivery hours", func(t *testing.T) { t.Run(tc.name, func(t *testing.T) { where tc.name is name: "Closing time is shown correctly when it's on the next day",
- Assistant
Thanks for the extra context!
Because your test hierarchy is:
gofunc TestGetDeliveryHours(t *testing.T) { t.Run("Returns correctly formatted delivery hours", func(t *testing.T) { t.Run(tc.name, func(t *testing.T) { // ... }) }) }and your subtest name is:
code"Closing time is shown correctly when it's on the next day"You need to specify the full path of test names separated by slashes
/:code