【发布时间】:2021-11-18 00:22:04
【问题描述】:
我是 Golang 新手,我正在尝试从 golang 应用程序运行一些测试。 测试在使用 Golang 1.12 的 docker 容器中运行。
我的问题是某些测试似乎运行正常,但其他测试却没有。
例子:
我有一个函数我想故意失败。
func TestLol(t *testing.T) {
assert.EqualValues(t, 1, 2)
t.Fail()
}
当我使用“docker run ... go test -v ./...”执行 docker 容器时,它应该运行所有测试,并且关于这个函数的特定它应该失败,但是它没有发生什么失败。 Golang 只是在测试旁边记录一个“ok”。
然后我尝试只运行包含应该失败的测试文件的文件夹。
日志:
ok github.com/eventials/csw-notifications/services 0.016s
2021/09/25 21:08:44 Command finished successfully.
Tests exited with status code: 0
Stopping csw-notifications_db_1 ... done
Stopping csw-notifications_broker_1 ... done
Going to remove csw-notifications_app_run_ed70597b5c20, csw-notifications_db_1, csw-notifications_broker_1
Removing csw-notifications_app_run_ed70597b5c20 ... done
Removing csw-notifications_db_1 ... done
Removing csw-notifications_broker_1 ... done
我的问题是,为什么 golang 不针对该文件输出任何带有 FAIL 消息的日志?
我认为这与这个问题有些相关,但由于它没有收到任何答复,我正在重新发布它。
Why the tests are not running ? ( Golang ) - goapp test - bug?
编辑:我正在对这个问题进行更清楚的编辑。
【问题讨论】:
-
你在哪个文件中添加了TestLol?你说“在这个例子中 /services/ 没有运行”。但是在输出的底部,它说
ok github.com/.../app/services 0.013s表示服务已运行并且所有测试都通过了。 -
我已经添加了两个文件。我说它没有运行,因为它应该失败,但它没有。所以我猜这个测试并没有通过所有的测试功能。
标签: unit-testing go testing