Visual Studio For Mac Unit Test

Live Unit Testing automatically runs any impacted unit tests in the background and shows your code coverage live in Visual Studio. As you modify your code, Live Unit Testing lets you know if your code changes are covered by existing tests or if you need to write new tests. Get gentle reminders to write new tests as you type. Oct 20, 2019 There are several unit test options available in Visual Studio 2019, but the decision to use MSTest for a particular project was out of my hands, so this post covers getting MSTest unit tests working on Visual Studio 2019 for Mac. The first step is to make sure you are using Visual Studio, and not confusing it with Visual Studio Code. My GearCamera -http://amzn.t.

There are several unit test options available in Visual Studio 2019, but the decision to use MSTest for a particular project was out of my hands, so this post covers getting MSTest unit tests working on Visual Studio 2019 for Mac.
The first step is to make sure you are using Visual Studio, and not confusing it with Visual Studio Code. The Visual Studio icon looks like this:
UnitAnd the Visual Studio Code icon looks like this:
Visual studio for mac debug unit test
Download visual studio for macThese instructions apply to Visual Studio (for Mac), not Visual Studio Code.
If you want to download a pre-loaded solution with a working example of an MSTest unit test, feel free to clone this GitHub repository and make any necessary changes. Replace the C# files with yours as needed (or just copy and paste contents). All of the Assert class methods can be found here; they are necessary to write other forms of unit test functions.
Important Note: If you clone the above repository, but have never added all of the NuGet testing plugins, the project will probably fail to build. The resolution is to follow the first half of the instructions below to install all of the necessary NuGet packages.

To update an existing project...

Visual Studio For Mac Live Unit Testing

If you run into trouble, it might help to clone the example repository above and compare your solution with mine.
Some guidance instructs you to create a separate sub-project under your project's solution to contain the unit test code. I suspect those instructions work properly for Visual Studio running on Windows, but there seem to be namespace issues in Visual Studio for Mac that prevents that approach from working correctly.
The solution is to apply all of the following instructions to the solution that your source files are stored in and not create a separate sub-project to contain the unit tests.
Add the proper unit test packages via NuGet. <ctrl>-click Dependencies and select Manage NuGet Packages...

Visual Studio For Mac




Use the search box in the upper right of that screen to find and add the following three packages:
  • Microsoft.NET.Test.Sdk
  • MSTest.TestAdapter
  • MSTest.TestFramework

Once you have added these packages, your solution will probably be broken with the following build message:
error CS0017: Program has more than one entry point defined. Compile with /main to specify the type that contains the entry point.
Many thanks to Andrew Lock for solving this one. His solution is geared towards xUnit, but it works in this case as well.
You should really read his incredibly detailed rundown; I did, and I learned a lot. But if you are short on time, the TL;DR is to add the following line of XML to any <PropertyGroup> section of your project's

Visual Studio For Mac Run Unit Tests

.csproj file:
<GenerateProgramFile>false</GenerateProgramFile>



And finally, to actually run the unit tests, select 'Run Unit Tests

Visual Studio Community For Mac

' from the 'Run' menu.

After you run the unit tests for the first time, you should have a button like this at the bottom of your IDE:
Click 'Test Results' to display the test results browser and debug any test failures.
Visual

In the current version of Visual Studio for Mac there is “Add file” template for xUnit Unit-Tests. Nice and easy. But how to run these tests? The problem is, that the default installation of Visual Studio for Mac does not discover these xUnit Tests even if you do a full rebuild.

Download Visual Studio For Mac

After searching a while I figured that one need to install the extension called “xUnit.NET 2 testing framework support” from the Extension Gallery.

After that one need to restart Visual Studio for Mac and do a full rebuild. The tests will then show up in the “Unit Tests” pad.