Visual Studio For Mac Unit Test

  1. Visual Studio For Mac Download
  2. Visual Studio For Mac Unit Test Project
  3. Visual Studio For Mac Unit Testing
  • This article will help you learn how to more easily test Xamarin.Forms applications with MSTest based unit tests and Xamarin.UITest based UI tests. As I’ve covered in previous posts, it is not possible to cover all the code in mobile applications, as well as UI applications in general, with tests based on console Unit Tests.
  • Visual Studio for Mac testing tools can help you and your team develop and sustain high standards of code excellence. Unit tests can be written and run using the Microsoft unit test framework (MSTest), xUnit, or NUnit.

Getting Started In Visual Studio For Mac. If you're using Visual Studio for Mac the NUnit templates extension can't be used. This guide assumes that you have a solution with either a PCL or a Shared project and a number of platform specific projects. Shared Test Project. First, create a new PCL that holds your shared testing code, so the. Unit Tests Pad success/fail glyphs not updated 0 Solution Mouse click way off (down) in latest update 1 Solution Visual Studio for Mac 2019 preview could not load unit tests in existing solution 2 Solution Firewall question repeatedly asked when running test on iOS simulator on Mac.

Last month at the AkronCodeClub they selected the magic square kata, which was a new one for me. Basically, you arrange 9 unique numbers in a 3x3 grid such that they add up to the same number horizontally, vertically and diagonally. I paired up with someone else who knew C#, so it was a good opportunity to try doing the kata in Visual Studio for Mac!

Visual Studio For Mac Unit Test

Although I've kicked the tires on VS4Mac a bit, one of the things I hadn't tried testing out was, well.. testing!

Method 1: An NUnit Library Project

The easiest method is to just create a new 'NUnit Library Project'. The VS4Mac team actually added a project type that includes the NUnit package and a test file out of the box. How convenient is that??

Create a new project

Go to: File / New Solution / Other / .NET / NUnit Library Project

Create a class and some tests

Like I said, there's already a 'Test.cs' file ready to go, with the proper NUnit attributes and everything. Go ahead and create a regular class and add a couple tests against it.

Run the tests

If you can't see the 'Unit Test' pane (or pad as they call it on the Mac), open it now: View / Pads / Unit Tests

You may need to click the build button (black triangle in upper-left) to see your new tests. Or just click the 'Run All' button in the Unit Tests pad.

Now change the logic so the tests fail (if they didn't already) and you can see the failure results in the 'Test Results' pad at the bottom. If you don't see that pad, open it now: View / Pads / Test Results

Visual Studio For Mac Download

That's it! If you're using VS4Mac for TDD during a code kata, it doesn't get much easier than that. :)

Method 2: Add NUnit to an Existing Project

But what if you already have a project and now you want to add tests to it? Let's start by creating a Library project to act as the 'existing project': File / New Solution / Other / .NET / Library

You should have a blank screen, along with the 'Solution' pad on the side of the screen. If you don't see that pad, go to: View / Pads / Solution

Create a Test File

Visual Studio For Mac Unit Test Project

Right-click your project and choose Add / New File. Select General / Empty Class and name it 'MagicSquareTests.cs'. I also repurposed the default 'MyClass.cs' as my MagicSquare class. You should end up with something like this:

Add the NUnit Package via NuGet

Right-click on Packages in the Solution pad and choose 'Add Packages'. All you need is NUnit - don't bother with the NUnit Console Runner.

You should see NUnit under the Packages folder.

Create a Few Tests

Add some new tests to run against whatever logic your old project has. In my case, I added a single function for the magic square kata, and wrote a couple tests against it that I was sure would fail.

The test runner tells you what failed and where.

Run / Observe / Fix / Repeat!

Try adding enough code to get your tests to pass, and run again.

More Reading

Visual Studio For Mac Unit Testing

If you'd like, you can read more about what I've discovered... or just download Visual Studio for Mac and try it out yourself!