'Auto run tests in visual studio code

How do I run the tests automatically in visual studio code. My project has testing setup, and the settings JSON/UI has settings related to auto running tests, but I don't see an option for the test to actually run automatically. I have found topics around this issue, but those seem to be out of date, or related to a (different) plugin.

settings



Solution 1:[1]

Since VSCode is a text editor rather than a fully-fledged IDE, tests are not a native feature. Testing frameworks also vary drastically between different programming languages or environments. I'd suggest looking into command-line tools such jest for JavaScript which you can run via VSCode's integrated terminal.

Another approach is to create a custom task to run your test. Find an example for jest here.

Solution 2:[2]

The Python support for VSCode is an extension, which does not fully support "all" the testing features. The "Testing > Auto Run" settings are currently missing. This issue is being tracked here. https://github.com/microsoft/vscode-python/issues/19046

Until this feature is properly implemented, the best way to achieve this uses extensions such as "Run on Save", the most popular item in the marketplace. https://marketplace.visualstudio.com/items?itemName=emeraldwalk.RunOnSave

"emeraldwalk.runonsave": {
    "commands": [
        {
            "match": "**.py",
            "isAsync": true,
            "cmd": "pytest"
        }
    ]
}

(disclosure, I work for MSFT and was investigating this issue prior to finding the question while doing my own research on alternatives)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 ExplosiveFridge
Solution 2 Dan Ciborowski - MSFT