onsi / ginkgo

A Modern Testing Framework for Go
http://onsi.github.io/ginkgo/
MIT License
8.32k stars 657 forks source link

Focus not running tests when using full name #1277

Closed tumberino closed 1 year ago

tumberino commented 1 year ago

Minimal example

package ginkgo_test

import (
    "testing"

    . "github.com/onsi/ginkgo/v2"
    . "github.com/onsi/gomega"
)

func TestExamples(t *testing.T) {
    RegisterFailHandler(Fail)
    RunSpecs(t, "Example Suite")
}

var _ = Describe("Example", func() {
    It("example pass", func() {
        Expect("A").To(Equal("A"))
    })
})

If I run ginkgo normally, the test runs and passes. Using ginkgo --junit-report=junit.xml to produce junit report I see the name of the test has been generated.

<testcase name="[It] Example example pass" classname="Example Suite" status="passed" time="4.6184e-05">

If I use the full testcase name as the argument for -focus e.g. ginkgo -focus "[It] Example example pass" the test gets skipped.

Will run 0 of 1 specs
S

Ran 0 of 1 Specs in 0.000 seconds
SUCCESS! -- 0 Passed | 0 Failed | 0 Pending | 1 Skipped

If I escape the [ and ] e.g. ginkgo -focus "\[It\] Example example pass". It still skips.

Will run 0 of 1 specs
S

Ran 0 of 1 Specs in 0.000 seconds
SUCCESS! -- 0 Passed | 0 Failed | 0 Pending | 1 Skipped

Only when I remove the [It] prefix does it select the correct test, ginkgo -focus "Example example pass"

Will run 1 of 1 specs
•

Ran 1 of 1 Specs in 0.000 seconds
SUCCESS! -- 1 Passed | 0 Failed | 0 Pending | 0 Skipped
PASS

Is there a better way to select the tests?

For background, trying to select the failed tests from the report and rerun them but selecting by test case name doesn't appear to work, as above.

onsi commented 1 year ago

hey there,

yes you'll need to strip the [It] from the test name. The full test name is just the concatenation of the container strings and the It string however for historical reasons that don't make too much sense any more, the JUnit report adds [It], however I'd rather not change that as it might break users who have come to rely on it/expect it.

This section of the docs lists all the ways you can filter specs.

tumberino commented 1 year ago

thanks I will see what can be done elsewhere