运行 go test -coverprofile 时出现“没有必需的模块提供包.out”错误

问题描述 投票:0回答:1

我正在尝试使用以下命令为我的 Go 项目生成代码覆盖率报告:

go test -coverprofile=coverage.out ./...

但是,我收到以下错误:

no required module provides package .out; to add it:
        go get .out

Go: "no required module provides package .out" error when running go test -coverprofile

我尝试过的: 已验证命令语法正确且没有多余空格。

Ran

go mod tidy
以确保所有依赖项均已正确安装。

重新启动终端并确保我位于正确的目录中。

为单个包运行命令:

go test -coverprofile=coverage.out .

这适用于当前包,但在所有带有

./...

的包上运行时,错误仍然存在

尝试指定

coverage.out
的完整路径,但没有帮助。

如何修复此错误并为项目中的所有包生成正确的测试覆盖率报告?

Ran

go mod tidy
以确保所有依赖项均已正确安装。

重新启动终端并确保我位于正确的目录中。

为单个包运行命令:

go test -coverprofile=coverage.out .

这适用于当前包,但在所有带有

./...

的包上运行时,错误仍然存在

尝试指定

coverage.out
的完整路径,但没有帮助。

开发环境:
操作系统:Windows 10
转到版本:1.23.1
模块系统 (

go.mod
) 已正确设置,并且依赖项已安装。

go
1个回答
0
投票

由于我使用的是 PowerShell,因此我需要在 -coverprofile 参数周围添加引号,以防止 PowerShell 误解该命令。

© www.soinside.com 2019 - 2024. All rights reserved.