go - 为什么这个 Go 代码输出 `testing: warning: no tests to run`?
问题描述
为什么这个 Go 代码输出testing: warning: no tests to run
?
package test
import (
"fmt"
"testing"
"github.com/stretchr/testify/assert"
)
func testCode(t *testing.T) {
arr := [2]string{"stringA", "stringB"}
fmt.Println(arr)
assert.Contains(t, arr, "stringB")
}
解决方案
你必须导出你的测试函数,所以它必须是func TestCode
(大写 T):
-func testCode(t *testing.T) {
+func TestCode(t *testing.T) {
arr := [2]string{"stringA", "stringB"}
fmt.Println(arr)
assert.Contains(t, arr, "stringB")
}
推荐阅读
- reactjs - 具有条件渲染和评估值的 jsx 表达式
- java - 使用 Apache Bcel 获取注释名称
- yocto - 将用户添加到 Yocto 中的现有组
- r - R studio - 如何粘贴代码块,但删除了注释?
- apache-spark - 如何在 JSON 中为 Spark 函数定义条件
- php - 将方法调用合并为一个调用
- javascript - 如何获取更新的 blob 列表?
- r - 为什么在 R 中绘制 png 时字符显示为 unicode 字符代码?
- firebase - rangeerror(索引):无效值:有效值范围为空:从firebase获取数据时为0
- python - 线程和 Tkinter /Python3