Active3 years, 2 months ago
- Nunit Visual Studio 2017
- Visual Studio For Mac Nunit Framework
- Visual Studio For Mac Unit Test
- Visual Studio For Mac Os X
I can't seem to get NUnit tests to run on our Mac build agent using VSTS
Here are the build steps I am using in VSTS:
Note, Test assemblies is disabled because the Mac build agent does not have VSTest.exe. In the options menu, there is no way to completely remove the need for VSTest so I cannot use that step on the mac build agent.
When you create a Unit Test App (Android) project in Visual Studio (or Android Unit Test project in Visual Studio for Mac), this project will not automatically run your tests by default. To run NUnit tests on a target device, you can create an Android.App.Instrumentation subclass that is started by using the following command: adb shell am instrument.
- Visual studio for mac sunilkp reported Apr 16 at 02:51 PM I am not able to see my test methods [nunit test methods defined with [Test] attribute] under View > Pads > Unit Tests pane.
- .NET Core test projects in Visual Studio for Mac 7.2 has a bug that would cause the test names to appear blank in the Unit Tests window. This problem was fixed in Visual Studio for Mac 7.3. This problem was fixed in Visual Studio for Mac 7.3.
Is there a way to run NUnit tests in the MSBuild step?
Nunit Visual Studio 2017
Things I have tried:
- Install NUnit test adapter in Visual Studio
- Install MSBuildTasks + Nunit MSBuild task (Not sure how to use it)
As a last resort, I can add a shell script to run nunit-console on the mac build agent, but I would prefer to avoid that. The reason the build agent needs mac os x is because we're building an iOS and Android app with Xamarin.
Screenshot of the references and NuGet packages in VS:
Build output:
Test assemblies are created, but I can't get them to run
Visual Studio For Mac Nunit Framework
Rishub NagpalRishub Nagpal![Visual Studio For Mac Nunit Visual Studio For Mac Nunit](/uploads/1/3/3/2/133274285/430931329.png)
48811 gold badge99 silver badges2727 bronze badges
![2017 2017](https://developercommunity.visualstudio.com/storage/attachments/33662-runtests.gif)
1 Answer
The instruction for how to use MSBuild tasks for NUnit can be found here: NUnit3 or NUnit. You need to update your project file to import the tasks according to this: Get Started and then add the NUnit MSBuild tasks into your project file. And you can also add an Exec Task in your project file to call NUnit console to run the NUnit test.
Eddie Chen - MSFTEddie Chen - MSFT25.7k22 gold badges2525 silver badges4848 bronze badges
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Not the answer you're looking for? Browse other questions tagged macosvisual-studiomsbuildnunitazure-devops or ask your own question.
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. It doesn't matter if you're using Xamarin.Forms or Xamarin.iOS/Xamarin.Android directly. Your solution might look something like this:
Shared Test Project
First, create a new PCL that holds your shared testing code, so the test code doesn't end up in production builds. Right Click on the Project Solution and Add a new project using the Cross-Platform Shared Library Template. Use Project.Tests as a name. Afterwards, your solution should look like this:
Edit the references of the newly created test project so that it contains a reference to the standard PCL. Afterwards, add a NuGet dependency on NUnit by right-clicking on Project.Tests and selection Add -> Add NuGet Package. Note: Ensure you reference the same version of NUnit as the version of nunit.xamarin you are using. e.g. If you are using nunit.xamarin 3.0.1, add the v3.0.1 NUnit NuGet package. Afterwards, your test project is ready.
Platform runners
In order to run the tests it's necessary to create a project for each platform you'd like to support (iOS, Android and so on). Do so using the standard Xamarin templates for new platform projects. It's probably sensible to use a naming scheme like Project.Tests.iOS for the individual test projects do keep your solution structured.
The NUnit.Xamarin runners are built using Xamarin.Forms, so you need to add NUnit, NUnit.Xamarin and Xamarin.Forms as NuGet dependencies to the newly created projects. It's also necessary to add a reference to the shared test project containing the tests.
If you've followed the steps above, you can now replace the AppDelegate.cs or MainActivity.cs with the code shown below. Since your tests are not in the same assembly as the runner it's a good idea to create a canary test class in the Shared Test Projects that you can use to reference the test assembly explicitly. In the example below, the name of this class is MyTest.cs.
Android
Visual Studio For Mac Unit Test
MainActivity.cs
Visual Studio For Mac Os X
iOS
AppDelegate.cs