英文:
Go cli cant find my tests
问题
当我尝试在Golang中运行我的测试时,我遇到了以下错误:
testing: 警告:没有要运行的测试
我还尝试创建一个测试项目,以查看它在其他项目中是否表现相同,这是我的两个文件:
package test
func test() string {
return "test"
}
这是我的测试:
package test
import (
"testing"
"github.com/stretchr/testify/assert"
)
func testTest(t *testing.T) {
assert.Equal(t, "test", test(), "String was not test")
}
我尝试使用以下命令运行它:
go test
go test -v
我还在Git Bash和命令提示符中测试了它的行为。
我使用的是Windows 10和Go 1.7.1。
希望有人能帮助我。
英文:
When i try to run my tests in golang i get the following error
testing: warning: no tests to run
I also tried to create a test project to see if it behaves the same in other projects these are my 2 files.
package test
func test() string {
return "test"
}
And here is my test.
package test
import (
"testing"
"github.com/stretchr/testify/assert"
)
func testTest(t *testing.T) {
assert.Equal(t, "test", test(), "String was not test")
}
I tried running it with:
go test
go test -v
Also i tested the behaviour in git bash and the cmd.
Im using Windows 10 with Go 1.7.1.
I hope somebody can help me.
答案1
得分: 3
测试函数必须以Test
开头。尝试将你的函数重命名为TestTest
。这样应该可以解决问题。完整信息请参考这里:https://golang.org/pkg/testing
英文:
Test functions must begin with Test
. Try renaming your function to TestTest
. That should fix it. Full info here: https://golang.org/pkg/testing
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论