{"id":31643,"date":"2023-02-01T16:00:45","date_gmt":"2023-02-01T16:00:45","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/cppblog\/?p=31643"},"modified":"2023-01-31T13:44:53","modified_gmt":"2023-01-31T13:44:53","slug":"remote-native-unit-test-support-in-visual-studio","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/cppblog\/remote-native-unit-test-support-in-visual-studio\/","title":{"rendered":"Remote Native Unit Test Support in Visual Studio"},"content":{"rendered":"<p>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.<\/p>\n<h2>How to Setup for Native Remote Unit Testing<\/h2>\n<h3>Prepare the Remote Windows Machine<\/h3>\n<p>1. Ensure <a href=\"https:\/\/learn.microsoft.com\/en-us\/windows\/win32\/projfs\/enabling-windows-projected-file-system\">Windows Projected File System<\/a> is enabled. You can run the following from an admin PowerShell window to enable it:<\/p>\n<p><code class=\"language-default\">Enable-WindowsOptionalFeature -Online -FeatureName Client-ProjFS -NoRestart<\/code><\/p>\n<p>Please restart the environment if required.<\/p>\n<p>2. Ensure SSH is setup. You can review the steps at <a href=\"https:\/\/learn.microsoft.com\/en-us\/windows-server\/administration\/openssh\/openssh_install_firstuse#install-openssh-using-powershell\">Install OpenSSH<\/a>. Start up the SSH server by running the following command from an admin PowerShell window:<\/p>\n<p><code class=\"language-default\">Start-Service sshd<\/code><\/p>\n<p>3. Ensure that .NET 5 or higher is installed on the remote machine. Downloads can be found <a href=\"https:\/\/dotnet.microsoft.com\/download\">here<\/a>.<\/p>\n<p>4. Ensure to install the appropriate <a href=\"https:\/\/learn.microsoft.com\/en-us\/cpp\/windows\/latest-supported-vc-redist?view=msvc-170\">Visual C++ Redistrubutable<\/a>.<\/p>\n<p>5. For debugging of tests:<\/p>\n<ul>\n<li>Please install the <a href=\"https:\/\/learn.microsoft.com\/en-us\/visualstudio\/debugger\/remote-debugging?view=vs-2022&amp;preserve-view=true\">Remote tools SKU<\/a> on the remote environment.<\/li>\n<li>Start up the remote debugger as an admin and ensure that the VS user has permissions to connect.<\/li>\n<\/ul>\n<h3>Prepare the C++ Unit Test Project in Visual Studio<\/h3>\n<p>1. Create a new Native Unit Test project:<\/p>\n<p><img decoding=\"async\" class=\"wp-image-31650\" src=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2023\/01\/graphical-user-interface-application-description-2.png\" alt=\"Graphical user interface, application Description automatically generated\" width=\"576\" height=\"300\" srcset=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2023\/01\/graphical-user-interface-application-description-2.png 3779w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2023\/01\/graphical-user-interface-application-description-2-300x156.png 300w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2023\/01\/graphical-user-interface-application-description-2-1024x534.png 1024w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2023\/01\/graphical-user-interface-application-description-2-768x401.png 768w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2023\/01\/graphical-user-interface-application-description-2-1536x801.png 1536w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2023\/01\/graphical-user-interface-application-description-2-2048x1068.png 2048w\" sizes=\"(max-width: 576px) 100vw, 576px\" \/><\/p>\n<p>2. You can add or remove SSH connections in\u00a0<strong><em>Tools &gt; Options &gt; Cross Platform &gt; Connection Manager<\/em><\/strong>. Selecting &#8220;Add&#8221; will allow you to enter the host name, port, and any credentials you need.<\/p>\n<p>3. The remote windows environment can be specified adding a <strong>testenvironments.json<\/strong> file to the root of your solution, using the following schema and replacing the <code>ssh:\/\/user@hostname:22<\/code>\u00a0with your SSH remoteUri.<\/p>\n<pre class=\"prettyprint language-json\"><code class=\"language-json\">{\r\n  \"version\": \"1\",\r\n  \"environments\": \r\n  [\r\n    {\r\n      \"name\": \"ssh-remote-arm64\", \/\/friendly name to help identify environment.\r\n      \"type\": \"ssh\",\r\n      \"remoteUri\": \"ssh:\/\/user@hostname:22\"\r\n    }\r\n  ]\r\n}\r\n<\/code><\/pre>\n<p>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.<\/p>\n<h2>Use the Test Explorer to Run and Debug Remote Unit Tests<\/h2>\n<p>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.<\/p>\n<p><img decoding=\"async\" class=\"wp-image-31651\" src=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2023\/01\/a-screenshot-of-a-computer-description-automatica-4.png\" alt=\"A screenshot of a computer Description automatically generated with medium confidence\" width=\"656\" height=\"198\" srcset=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2023\/01\/a-screenshot-of-a-computer-description-automatica-4.png 1632w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2023\/01\/a-screenshot-of-a-computer-description-automatica-4-300x90.png 300w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2023\/01\/a-screenshot-of-a-computer-description-automatica-4-1024x309.png 1024w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2023\/01\/a-screenshot-of-a-computer-description-automatica-4-768x232.png 768w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2023\/01\/a-screenshot-of-a-computer-description-automatica-4-1536x463.png 1536w\" sizes=\"(max-width: 656px) 100vw, 656px\" \/><\/p>\n<p>2. Once an environment is selected, tests are discovered and run in the new environment.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2023\/01\/Picture1-1.png\"><img decoding=\"async\" class=\"wp-image-31656 alignnone\" src=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2023\/01\/Picture1-1.png\" alt=\"Image Picture1\" width=\"661\" height=\"344\" srcset=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2023\/01\/Picture1-1.png 1061w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2023\/01\/Picture1-1-300x156.png 300w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2023\/01\/Picture1-1-1024x533.png 1024w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2023\/01\/Picture1-1-768x400.png 768w\" sizes=\"(max-width: 661px) 100vw, 661px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<h2>Give us your Feedback<\/h2>\n<p>Download the latest <a href=\"https:\/\/visualstudio.microsoft.com\/vs\/preview\/vs2022\/\">Visual Studio 2022 Preview<\/a> today and give it a try. For more information about remote unit testing for Windows, check out <a href=\"https:\/\/learn.microsoft.com\/en-us\/visualstudio\/test\/remote-testing?view=vs-2022\">Remote Testing in Visual Studio &#8211; Visual Studio (Windows) | Microsoft Learn<\/a>. We\u2019d love to hear from you to help us prioritize and build the right features for you. We can be reached via the comments below, <a href=\"https:\/\/developercommunity.visualstudio.com\/spaces\/8\/index.html\">Developer Community<\/a>, and Twitter (<a href=\"https:\/\/twitter.com\/visualc\">@VisualC<\/a>). The best way to file a bug or suggest a feature is via Developer Community.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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 [&hellip;]<\/p>\n","protected":false},"author":53792,"featured_media":35994,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-31643","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-cplusplus"],"acf":[],"blog_post_summary":"<p>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 [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/posts\/31643","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/users\/53792"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/comments?post=31643"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/posts\/31643\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/media\/35994"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/media?parent=31643"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/categories?post=31643"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/tags?post=31643"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}