Wayback Machine
32 captures
08 Jun 2023 - 04 Jul 2025
Jul SEP Nov
Previous capture 30 Next capture
2022 2023 2024
success
fail
About this capture
COLLECTED BY
Collection: Common Crawl
Web crawl data from Common Crawl.
TIMESTAMPS
loading
The Wayback Machine - https://web.archive.org/web/20230930155937/https://code.visualstudio.com/docs/csharp/testing
Skip to content  Visual Studio Code
  • Docs
  • Updates
  • Blog
  • API
  • Extensions
  • FAQ
  • Learn
  • Search
  • Search Search
  • Download VS Code Download VS Code Download

Version 1.82 is now available! Read about the new features and fixes from August.

Dismiss this update
'; document.body.appendChild(div.children[0]); } function pushCodingPackEvent(language, os) { let id = `${language}-${os}-coding-pack`; var analytics = window.vscodeAnalytics; analytics && analytics.event( 'click', 'download', id, ); }
  • Overview
  • Setup
    • Overview
    • Linux
    • macOS
    • Windows
    • Raspberry Pi
    • Network
    • Additional Components
    • Enterprise
    • Uninstall
  • Get Started
    • Intro Videos
    • Tips and Tricks
    • User Interface
    • Themes
    • Settings
    • Key Bindings
    • Display Language
    • Telemetry
  • User Guide
    • Basic Editing
    • Extension Marketplace
    • IntelliSense
    • Code Navigation
    • Refactoring
    • AI Tools
    • Debugging
    • VS Code for the Web
    • Tasks
    • Profiles
    • Settings Sync
    • Snippets
    • Emmet
    • Command Line Interface
    • Workspace Trust
    • Multi-root Workspaces
    • Accessibility
    • Port Forwarding
  • Source Control
    • Overview
    • Introduction to Git
    • Collaborate on GitHub
    • FAQ
  • Terminal
    • Terminal Basics
    • Terminal Profiles
    • Shell Integration
    • Appearance
    • Advanced
  • Languages
    • Overview
    • JavaScript
    • JSON
    • HTML
    • CSS, SCSS and Less
    • TypeScript
    • Markdown
    • PowerShell
    • C++
    • Java
    • PHP
    • Python
    • Julia
    • R
    • Ruby
    • Rust
    • Go
    • T-SQL
    • C#
    • .NET
    • Polyglot
  • Node.js / JavaScript
    • Working with JavaScript
    • Node.js Tutorial
    • Node.js Debugging
    • Deploy Node.js Apps
    • Browser Debugging
    • Angular Tutorial
    • React Tutorial
    • Vue Tutorial
    • Debugging Recipes
    • Performance Profiling
    • Extensions
  • TypeScript
    • Tutorial
    • Compiling
    • Editing
    • Refactoring
    • Debugging
  • Python
    • Tutorial
    • Editing Code
    • Linting
    • Formatting
    • Debugging
    • Environments
    • Testing
    • Python Interactive
    • Django Tutorial
    • Flask Tutorial
    • Create containers
    • Deploy Python Apps
    • Python in the Web
    • Settings Reference
  • Java
    • Getting Started
    • Navigate and Edit
    • Refactoring
    • Formatting and Linting
    • Project Management
    • Build Tools
    • Run and Debug
    • Testing
    • Spring Boot
    • Application Servers
    • Deploy Java Apps
    • GUI Applications
    • Extensions
    • FAQ
  • C++
    • Intro Videos
    • GCC on Linux
    • GCC on Windows
    • GCC on Windows Subsystem for Linux
    • Clang on macOS
    • Microsoft C++ on Windows
    • Build with CMake
    • CMake Tools on Linux
    • Editing
    • Debugging
    • Configure debugging
    • Settings
    • Configure IntelliSense for cross-compiling
    • FAQ
  • C#
    • Get Started
    • Navigate and Edit
    • IntelliCode
    • Refactoring
    • Formatting and Linting
    • Project Management
    • Build Tools
    • Package Management
    • Run and Debug
    • Testing
    • FAQ
  • Docker
    • Overview
    • Node.js
    • Python
    • ASP.NET Core
    • Debug
    • Docker Compose
    • Registries
    • Deploy to Azure
    • Choose a dev environment
    • Customize
    • Develop with Kubernetes
    • Tips and Tricks
  • Data Science
    • Overview
    • Jupyter Notebooks
    • Data Science Tutorial
    • Python Interactive
    • PyTorch Support
    • Azure Machine Learning
    • Manage Jupyter Kernels
    • Jupyter Notebooks on the web
  • Azure
    • Extensions
    • Deployment
    • Remote Debugging for Node.js
    • Docker
    • MongoDB
    • Kubernetes
    • Azure Kubernetes Service
  • Remote
    • Overview
    • SSH
    • Dev Containers
    • Windows Subsystem for Linux
    • GitHub Codespaces
    • VS Code Server
    • Tunnels
    • SSH Tutorial
    • WSL Tutorial
    • Tips and Tricks
    • FAQ
  • Dev Containers
    • Overview
    • Tutorial
    • Attach to Container
    • Create a Dev Container
    • Advanced Containers
    • devcontainer.json
    • Dev Container CLI
    • Tips and Tricks
    • FAQ
Edit

Testing with C# Dev Kit

Testing in C# in Visual Studio Code is enabled by the C# Dev Kit extension. It's a lightweight extension to enhance your C# development experience.

Overview

The extension supports the following test frameworks:

  • xUnit
  • NUnit
  • MSTest

The C# Dev Kit extension provides the following features:

  • Run/Debug tests cases
  • View test report
  • View tests in Testing Explorer

Requirements

  • .NET 6.0 SDK or later
  • Visual Studio Code (version 1.58.0 or later)
  • C# Dev Kit

Project setup

Note: If you have already set up your C# test framework in your project, you can skip to the Features section.

Enable testing and adding test framework packages to your project

You can enable a test framework for your project with just a few steps in the Solution Explorer:

xUnit

Open the Command Palette and select .NET:New Project.. then select xUnit Test Project and provide name and location for the new project. This will create a new project and directory that uses xUnit as the test library and configures the test runner by adding the following <PackageReference /> elements to the project file.

  • Microsoft.NET.Test.Sdk
  • xunit
  • xunit.runner.visualstudio
  • coverlet.collector

From the Terminal, run the following command:

dotnet add [location of your test csproj file] reference [location of the csproj file for project to be tested]

NUnit

Open the Command Palette and select .NET:New Project.. then select NUnit3 Test Project and provide name and location for the new project. This will create a new project and directory that uses NUnit as the test library and configures the test runner by adding the following <PackageReference /> elements to the project file.

  • Microsoft.NET.Test.Sdk
  • nunit
  • NUnit3TestAdapter

From the Terminal, run the following command:

dotnet add [location of your test csproj file] reference [location of the csproj file for project to be tested]

MSTest

Open the Command Palette and select .NET:New Project.. then select MSTest Test Project and provide name and location for the new project. This will create a new project and directory that uses MSTest as the test library and configures the test runner by adding the following <PackageReference /> elements to the project file.

  • Microsoft.NET.Test.Sdk
  • MSTest.TestAdapter
  • MSTest.TestFramework
  • coverlet.collector

From the Terminal, run the following command:

dotnet add [location of your test csproj file] reference [location of the csproj file for project to be tested]

Features

Run/Debug test cases

C# Dev Kit will generate shortcuts (the green play button) on the left side of the class and method definition. To run the target test cases, select the green play button. You can also right-click on it to see more options.

Test Explorer

The Test Explorer is a tree view to show all the test cases in your workspace. You can select the beaker button on the left-side Activity bar of Visual Studio Code to open it. You can also run/debug your test cases and view their test results from there.

View test results

After running/debugging the test cases the state of the related test items will be updated in both editor decorations and the Test Explorer.

View test results

You can select the links in the stack trace to navigate to the source location.

VS Code testing commands

There are testing commands (for example, Run All Tests) that can be found by searching for Test: in the Command Palette (⇧⌘P (Windows, Linux Ctrl+Shift+P)).

Testing command in Command Palette

VS Code testing settings

There are VS Code settings specific to testing that can be found by searching for Testing in the Settings editor (⌘, (Windows, Linux Ctrl+,)).

Testing settings

6/6/2023

In this article there are 4 sectionsIn this article

  • Overview
  • Requirements
  • Project setup
  • Features
  • Hello from Seattle.
  • Follow @code
  • Support
  • Privacy
  • Manage Cookies
  • Terms of Use
  • License
Microsoft homepage Microsoft homepage © 2023 Microsoft