February 1st, 2023

Remote Native Unit Test Support in Visual Studio

Moyo Okeremi
Software Engineer II

Remote C++ unit testing enables developers to connect Visual Studio 2022 to remote windows environments for running and debugging C++ desktop application tests. This functionality is useful for developers who deploy code to different Windows target environments such as different Windows architectures. With this feature, you can run tests on your target machine right from Visual Studio by connecting the Test Explorer to a remote environment.

How to Setup for Native Remote Unit Testing

Prepare the Remote Windows Machine

1. Ensure Windows Projected File System is enabled. You can run the following from an admin PowerShell window to enable it:

Enable-WindowsOptionalFeature -Online -FeatureName Client-ProjFS -NoRestart

Please restart the environment if required.

2. Ensure SSH is setup. You can review the steps at Install OpenSSH. Start up the SSH server by running the following command from an admin PowerShell window:

Start-Service sshd

3. Ensure that .NET 5 or higher is installed on the remote machine. Downloads can be found here.

4. Ensure to install the appropriate Visual C++ Redistrubutable.

5. For debugging of tests:

  • Please install the Remote tools SKU on the remote environment.
  • Start up the remote debugger as an admin and ensure that the VS user has permissions to connect.

Prepare the C++ Unit Test Project in Visual Studio

1. Create a new Native Unit Test project:

Graphical user interface, application Description automatically generated

2. You can add or remove SSH connections in Tools > Options > Cross Platform > Connection Manager. Selecting “Add” will allow you to enter the host name, port, and any credentials you need.

3. The remote windows environment can be specified adding a testenvironments.json file to the root of your solution, using the following schema and replacing the ssh://user@hostname:22 with your SSH remoteUri.

{
  "version": "1",
  "environments": 
  [
    {
      "name": "ssh-remote-arm64", //friendly name to help identify environment.
      "type": "ssh",
      "remoteUri": "ssh://user@hostname:22"
    }
  ]
}

Once your connection is in the connection manager, as you type the info into the testEnvironments.json file, Intellisense will assist you by showing you your different available connections and you can select the appropriate one.

Use the Test Explorer to Run and Debug Remote Unit Tests

1. The active environment is selected via a drop-down in the Test Explorer tool bar. Currently, only one test environment can be active at a time.

A screenshot of a computer Description automatically generated with medium confidence

2. Once an environment is selected, tests are discovered and run in the new environment.

Image Picture1

 

Give us your Feedback

Download the latest Visual Studio 2022 Preview today and give it a try. For more information about remote unit testing for Windows, check out Remote Testing in Visual Studio – Visual Studio (Windows) | Microsoft Learn. We’d love to hear from you to help us prioritize and build the right features for you. We can be reached via the comments below, Developer Community, and Twitter (@VisualC). The best way to file a bug or suggest a feature is via Developer Community.

Category
C++

Author

Moyo Okeremi
Software Engineer II

Moyo Okeremi is a software engineer on the Visual Studio C++ Cross Platform team.

2 comments

Discussion is closed. Login to edit/delete existing comments.

  • Mark Radcliffe

    Hi,

    This looks interesting, is this possible for C# projects also?

    This could be a good tool for remotely testing using lower powered laptops for large projects, enabling offloading of the testing to a network server for development time testing.

    Cheers

    • Mark Radcliffe

      Nevermind I see this is already supported recently

      Remote testing for C#