Go命令行找不到我的测试。

huangapple go评论85阅读模式
英文:

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

huangapple
  • 本文由 发表于 2017年2月12日 04:43:32
  • 转载请务必保留本文链接:https://go.coder-hub.com/42181009.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定