Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run all tests in Visual Studio Code

The latest version of VS Code already provides an easy way of running a single test as pointed on Tyler Long's answer to the question Debugging xunit tests in .NET Core and Visual Studio Code.

However, I am looking how can I run all tests contained in a test suite class in VS Code (without debug)?

The only way I found was adding to launch.json a specific configuration as the following one, but which I can only run in debug (I would like to run it without debug):

{
  "name": ".NET Core Xunit tests",
  "type": "coreclr",
  "request": "launch",
  "preLaunchTask": "build",
  "program": "/usr/local/share/dotnet/dotnet",
  "args": ["test"],
  "cwd": "${workspaceRoot}/test/MyProject.Tests",
  "externalConsole": false,
  "stopAtEntry": false,
  "internalConsoleOptions": "openOnSessionStart"
}
like image 595
Miguel Gamboa Avatar asked Jan 31 '17 13:01

Miguel Gamboa


People also ask

How do I run all test cases in Visual Studio?

To run all the tests in a default group, choose the Run icon and then choose the group on the menu. Select the individual tests that you want to run, open the right-click menu for a selected test and then choose Run Selected Tests (or press Ctrl + R, T).

Can you run tests in VS Code?

In the generated extension, you can use npm run test or yarn test to run the integration tests that: Downloads and unzips latest version of VS Code. Runs the Mocha tests specified by the extension test runner script.

How do you run a test class in VS Code?

Run Apex Tests In Visual Studio Code, click the View menu then choose Command Palette.... Alternatively, you can use the keyboard shortcut Ctrl+Shift+P (Windows or Linux) or Cmd+Shift+P (macOS) to open the Command Palette. Enter apex test in the search box, then choose SFDX: Run Apex Tests.


2 Answers

There is a much easier way to run all tests:

  1. Install the .NET Core Test Explorer extension
  2. Open a .NET Core test project in VS Code, or set dotnet-test-explorer.testProjectPath to the folder path of .NET Core test project in settings.json
  3. In .NET Test Explorer of Explorer view, all the tests will be automatically detected, and you are able to run all tests or a certain test

.NET Test Explorer

like image 156
Jun Han Avatar answered Oct 09 '22 19:10

Jun Han


You can run all tests in a project by executing dotnet test on the terminal. This is handy if you already have the terminal open, but you can add it to Visual Studio code as well.

If you press Cmd-Shift-P to open the Command Palette and type "test", you can run the Run Test Task command. By default, this doesn't do anything, but you can edit tasks.json to tell it how to run dotnet test for you:

tasks.json

{
  "version": "0.1.0",
  "command": "dotnet",
  "isShellCommand": true,
  "args": [],
  "tasks": [
    {
      "taskName": "build",
      "args": [ ],
      "isBuildCommand": true,
      "showOutput": "silent",
      "problemMatcher": "$msCompile"
    },
    {
      "taskName": "test",
      "args": [ ],
      "isTestCommand": true,
      "showOutput": "always",
      "problemMatcher": "$msCompile"
    }
  ]
}

These two task definitions will link the Run Build Task and Run Test Task commands in Visual Studio Code to dotnet build and dotnet test, respectively.

like image 22
Nate Barbettini Avatar answered Oct 09 '22 17:10

Nate Barbettini