Visual Studio Code的“运行测试 | 调试测试”选项在单元测试中丢失。

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

Visual Studio Code's "Run Test | Debug Test" option missing from unit tests

问题

我曾经在VS Code中的每个Go测试函数的顶部看到"Run Test | Debug Test"链接。但现在它们不见了。我该如何重新启用它们?

这张图片展示了我所说的内容:

Visual Studio Code的“运行测试 | 调试测试”选项在单元测试中丢失。

英文:

I used to see "Run Test | Debug Test" links top of every test function in VS Code for Go. But they are missing now. How can I re-enable them?

This picture shows what I am talking about:

Visual Studio Code的“运行测试 | 调试测试”选项在单元测试中丢失。

答案1

得分: 3

直接从go.devtesting包文档中获取的信息:

  • 要编写一个新的测试套件,请创建一个文件,文件名以_test.go结尾,并包含如下所述的TestXxx函数。将该文件放在与被测试的包相同的包中。

请确保您的测试文件名以_test.go结尾,并且您要测试的函数以Test开头(就像在您的代码片段中一样)。

英文:

Taken directly from the go.dev doc for the testing package

  • To write a new test suite, create a file whose name ends _test.go that contains the TestXxx functions as described here. Put the file in the same package as the one being tested.

Please ensure that your test file name ends in _test.go, and that the function you're trying to test starts with Test (like it does in your snippet).

答案2

得分: 1

请确认您的选项,以确保Go测试资源管理器已启用:

  • 首选项 > 设置 > 用户设置 > 查找"go test enable code lens"

  • Visual Studio Code的“运行测试 | 调试测试”选项在单元测试中丢失。

英文:

Check your options to confirm that the Go test explorer is enabled:

  • Preferences > Settings > User Settings > find "go test enable code lens"

Visual Studio Code的“运行测试 | 调试测试”选项在单元测试中丢失。

答案3

得分: 0

我在VSCode中打开的项目中有很多文件夹,但只有当我在新窗口中打开包含我想要运行测试脚本的文件夹时,这些选项才会出现。我不知道为什么,这很奇怪。

英文:

I have this situation when there are many folders in the project I opened in VScode. But these options appear only when I open the folder containing the script I want to run the test in in a new window in VSCode. I don't know why, it's weird.

答案4

得分: -1

今天我遇到了同样的问题。在我的情况下,打开命令面板(Ctrl+Shift+P),然后运行"OmniSharp: Restart OmniSharp"解决了这个问题。

英文:

Had the same issue today. In my case opening the Command Palette (Ctrl+Shift+P) and running "OmniSharp: Restart OmniSharp" fixed it.

答案5

得分: -1

同样的情况也发生在我这里 - 只是关闭了VS Code,然后重新打开它...它们又都出现了。

英文:

Same thing here - simply closed down VS Code and opened it back up again... they all appeared once more.

答案6

得分: -1

这件事发生在我身上,尽管我当时在写JavaScript(而不是Go)。

为了解决这个问题,我需要确保ES6的importexport语句是正确的(从正确的文件路径中正确地导入正确的项目),对于当前的测试JavaScript文件和相关导入的JavaScript文件(甚至是当前项目中的所有文件)。

(然后你必须保存测试JavaScript文件以刷新它。)

Test ExplorerOutput面板可能(?)会抛出错误来指示这个问题。

英文:

This happened to me, though I was writing Javascript (not Go).

To fix that, I need to make sure the Es6 import & export statements are correct (-- correctly importing the correct item from the correct file path),, -- for this current test js file & relevant imported js files (or even all files in current project).

(Then you must save the test js file to refresh it.)

The Test Explorer's Output panel may(?<) throw an Error to indicate that.

答案7

得分: -1

除了重新启动OmniSharp,您可能还希望确保选择了正确的解决方案。
按下Ctrl + Shift + P键,选择OmniSharp: Select Project,然后选择您解决方案的正确.sln文件。

英文:

In addition to restating OmniSharp, you might want to make sure the right solution is selected.
Ctrl + Shift + P > select OmniSharp: Select Project > select the correct .sln file for your solution

huangapple
  • 本文由 发表于 2022年4月22日 17:53:08
  • 转载请务必保留本文链接:https://go.coder-hub.com/71966822.html
匿名

发表评论

匿名网友

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

确定