unit-testing - Go 客户端找不到我的测试

标签 unit-testing testing go

<分区>

当我尝试在 golang 中运行我的测试时,出现以下错误

testing: warning: no tests to run

我还尝试创建一个测试项目,看看它在其他项目中的行为是否相同,这是我的 2 个文件。

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 和 cmd 中的行为。 我在 Windows 10 中使用 Go 1.7.1。

我希望有人能帮助我。

最佳答案

测试函数必须以 Test 开头。尝试将您的函数重命名为 TestTest。那应该解决它。此处提供完整信息:https://golang.org/pkg/testing

关于unit-testing - Go 客户端找不到我的测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42181009/

相关文章:

angular - 为什么我收到此错误 : NullInjectorError: R3InjectorError(DynamicTestModule)[MedicoService?

ios - 使用 Selenium 和 ios-driver 从 Windows 计算机测试 iOS 移动应用程序

go - 使用 StreamClientInterceptor 确定 RPC session 何时结束的最佳方法是什么?

ios - 私有(private)属性(property)上的 OCUnit

unit-testing - VSTS : dotnet with Docker fail to publish tests

swift - Xcode:如果前一个失败则跳过测试

循环中的 bufio ReadString 是无限的

mongodb - 我如何在mongodb中找到附近的纬度和经度?

python - 如何使用生成器参数验证 Python 模拟调用

ruby - RSpec 在带参数的方法上测试 ArgumentError