[Go] Testing when solving go test: warning: no tests to run

When executing a specified function of go test, the report: testing: warning: no tests to run

For example go test -v -run Mytest

 

The test file name must be this _test suffix

xxxx_test.go

 

If it is not designated to run by correspondence, then the test function must start with Test

For example, the following file can

package tools

import (
    " fmt " 
    " testing "
)

func TestMytest(t * testing.T) {
    Mytest()
}
func Mytest() {
    m: = make(map[ string ] string )
    m[ " a " ] = " b "

    m2: = make(map[ string ] interface {})
    m2[ " a " ] = " b "
    test(m2)
    a: = " aaa "
    test2(a)
}

func test(t map[ string ] interface {}) {
    fmt.Printf( " %T " , t)
}
func test2(t interface {}) {
    fmt.Printf( " %T " , t)
}

 There are two ways of execution

 

go test -v test_test.go

go test -v -run Mytest

Read More:

Leave a Reply

Your email address will not be published. Required fields are marked *