1

I am trying to switch to VS Code from LiteIDE for developing GO code. One of the features that I used frequently in LiteIDE was the ability to pick a file, other than the current file, as the target of run or test commands.

For example, I could set the file my_go_file_test.go as the target and then be able to run the tests with a keyboard shortcut while editing any other file.

In LiteIDE this is accomplished by pinning the file in a control at the top of the IDE. Is there a way to do something similar in VS Code.

I've poked around in setting and googled it. The best I can come up with at this point is a three-step process to toggle to the test file, run the test, and then toggle back to the file I was in. This requires 3 separate shortcuts instead of just one.

The goal is to be able to use a single keyboard shortcut to run tests while doing TDD.

Justin Ohms
  • 3,334
  • 31
  • 45
  • Why do you have to toggle to another file in the editor? The go tool operates on packages, so individual files don’t matter. – JimB Apr 06 '20 at 01:09
  • I fail to see how you intend this to work, since the test file shouldn’t contain the code that’s being tested. What exactly do you want VSCode to execute? If you only want test one thing, run a single test – JimB Apr 06 '20 at 01:45
  • @JimB If you are editing in a package and your execute package-level tests it will run all tests for that package. But maybe I don't want to run all the package tests, only the tests contained in a particular file. Or as another example, I might be editing code in one package but want to run a test file from a completely different package that calls it. – Justin Ohms Apr 06 '20 at 02:22
  • You can run specific tests with Go, but again that has nothing to do with a filename, because the go tool operates on packages. Maybe LiteIDE looked at the file contents and only ran those tests, but asking to test a specific file doesn’t make sense in Go. – JimB Apr 06 '20 at 02:32
  • Yes, this is exactly what LiteIDE does. GoLand from JetBrains does the same thing. So I'm looking for the same functionality in VSCode. Testing a single file is fairly common. VSCode actually already supports it with the "Go: Test File" pallet command. The only difference is that in VSCode there is no way to point "Go: Test File" to a file other than the current file. This is the missing functionality. Both GoLand and LiteIDE have this capability. – Justin Ohms Apr 06 '20 at 03:21
  • You have to create a custom "task", see https://code.visualstudio.com/Docs/editor/tasks. Then you can bind the keyboard shortcut you prefer, still explained in the link above. – marco.m Apr 06 '20 at 08:34
  • OK, it appears to just list a bunch of regexes matching the tests in a particular file. Once you run a set of tests from the current file, you can repeat that with `Go: Test Previous`. – JimB Apr 06 '20 at 13:25

0 Answers0