srls01
srls01

Reputation: 613

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

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:

enter image description here

Upvotes: 5

Views: 27205

Answers (7)

Zeray K. Mehari
Zeray K. Mehari

Reputation: 1

I have managed to fix it. The problem was on pom.xml's java settings. The java version I am using is 17 not 1.7 and I changed the setting in pom.xml to 17. And voila!

Upvotes: -2

protaru
protaru

Reputation: 29

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

Upvotes: -1

srls01
srls01

Reputation: 613

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.

Upvotes: 0

Nor.Z
Nor.Z

Reputation: 1349

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.

Upvotes: 1

Drew
Drew

Reputation: 497

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

Upvotes: 0

Joost
Joost

Reputation: 490

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

Upvotes: -1

Matthew Gower
Matthew Gower

Reputation: 55

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).

Upvotes: 2

Related Questions