C# TestClass on Mac - c#

I am trying to get a file working on OS X which requires the use of the [TestClass()] and [TestMethod()] attributes. Im new to c# (Ive used java for a few years now) so Im not sure, but I think these attributes are part of Microsoft.VisualStudio. Since I'm on OS X I an using mono to compile and run C# files. How, if possible, can I get the same functionality as the Microsoft.VisualStudio.TestTools.UnitTesting namespace?

Xamarin Studio / Monodevelop has a unit testing add-in which allows running NUnit tests within the IDE. The add-in should be installed by default. If not, you can install it through Tools > Add-ins.
When you build a class that has [TestFixture] attribute and it has a method with [Test] attribute - you can run it from View > Pads > Unit Tests or green icon at signature line. In this screenshot, lines 12 and 26:
Additionally, there should be a project template which already has NUnit package pre-installed and a test class ready:

[TestClass()] and [TestMethod()] are part of MSTest framework and are not available in Mono.
Have you looked at using a mono build of Nunit you can also use "using mapping" to convert you ms test attributes to nunit here is an example http://www.martinwilley.com/net/code/nunitmstest.html
If using mono isn't a requirement, you could also look at using .NET Core it's still in development but it's the full .net stack by Microsoft for OSX and Linux

Related

NUnit Test Adapter 3 cannot seem to find NUnit3 Framework causing Test Explorer to not show Test

I have a project where I have packaged the NUnit3 Framework along with some others into an internal dll. However when I reference the dll in a project I unable to get TEST to show in the Visual Studio 15, Test Explorer.
Inside the project classes I am able to use NUnit.Framework methods. I think the issue has to do with the NUnitTestAdapter3, not able to find the reference to the NUnit3Framework. Because after I remove the Nunit3 Framework from my DLL and just add NUnit3 Framework and NUnit 3 Test Adapter to my project, I am able to get the test to show. So I am guessing there is disconnect between NUnit3 Test Adapter package and my DLL which contains NUnit3 Framework..
Is there a way to be able to have the NUnit3 Test Adapter reference the NUnit3 Framework in my custom DLL to get these to show?
The problem is not in the adapter but in the NUnit Test Engine, which it uses. The engine has code to determine what framework is in use. That code actually depends on the name of the framework.
Under NUnit V2, we tried to load whatever assembly you pointed to. But with NUnit 3, the engine has to figure out what framework is in use, since it supports multiple frameworks through extensions.
There's currently no way around this. You need to use the actual nunit.framework assembly.

No test is available in <path>\PKGS\Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll

I am using .NET framework 4.5 and C# for my project and i used mstest for Test project. All unit test cases ran fine on Visual Studio 2017 enterprise edition, but when I created Jenkins for the Unit test, some of tests are executed and in middle the build fails saying:
No test is available in
\PKGS\Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll.
Make sure that test discoverer & executors are registered and platform
& framework version settings are appropriate and try again
Additionally, path to test adapters can be specified using
/TestAdapterPath command. Example
/TestAdapterPath:. vstest.console.exe
F:\jnks\workspace\mPrint_Roam_Horizon_Inc\PKGS\Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.dll
/InIsolation /EnableCodeCoverage
The error says that the file Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll does not contain any tests (which is correct, because it is a frameworkfile). You probably have some errors in the path where you are looking for dll's with tests in them.

.NET unit test run without Visual Studio

I have build the unit test DDL on my machine and run on the another place without installing visual studio.
To do this, I install the NUnit command line and call the my unit test DLL, and it does not work.
In my C# code I only add the [TestMethod] attribute on my test method.
The below image shows how I call the NUnit on the command line:
Is there an issue in here, or is there any other way to do this?
Note: I use the Selenium library in my project.
The NUnit console runner is made to run NUnit tests, that is, tests that use the NUnit framework. Since you are using the [TestMethod] attribute, you are probably using Microsoft's test framework.
NUnit used to be delivered (version 2) as a single package, but with version 3 it is divided into several different packages. You will have to download and reference the NUnit framework and change your tests to use its attributes and assertions.

Unit test UWP app with NUnit on VS2015

I spent far too much time trying to run a basic NUnit test on a Microsoft Store app. I installed NUnit v3.0.1 and NUnit3TestAdapter on VS2015 Pro but I get the following which confirms that the test is not discovered:
------ Discover test started ------
NUnit Adapter 3.0.8.0 discovering tests is started
Exception NUnit.Engine.NUnitEngineException, Exception thrown discovering tests in <project exe file>
The NUnit 3.0 driver does not support the portable version of NUnit. Use a platform specific runner.
NUnit Adapter 3.0.8.0 discovering test is finished
========== Discover test finished: 0 found (0:00:01.0639991) ==========
The NUnit.Engine.NUnitEngineException error referred to is not helpful because there is no way of exploring where the exception is in my program. The test is a single method with one Assert statement just to test if the setup works so there is nothing complicated. I also don't understand what a "platform specific runner" is. I installed both NUnit and NUnit3TestAdapter thru NuGet Package Manager and I presume installations for relevant platform and version are carried out.
I even tried out installing "NUnit Templates for Visual Studio". This allowed me to create an NUnit project, and interestingly the test within NUnit project is discovered and run. But the downside is that I cannot reference my UWP app project from the working NUnit project, I think because the NUnit project only supports .Net frameworks (up to 4.6.1) not Windows 10 platforms.
I have used NUnit before for non UWP applications without much trouble. Am I missing something or NUnit as yet doesn't support UWP apps?
At the moment you can only test DNX projects with XUnit.
Here is a nice starting point for that.
From the official Asp.Net 5 documentation (which uses the same infrastructure as UWP):
For example, to work with the xUnit test framework, you would
configure the dependencies as follows: [example project.json I dont
want to copy]
As other test frameworks release support for DNX, we
will link to them here.
Since there are no other frameworks linked in the documentation, I assume that there are none that support DNX projects at the moment.
Since this question was originally posted NUnit has developed it's support for testing UWP/Xamarin apps. Check out the nunit.xamarin runners.
Essentially, your tests should be created in either a portable library, or a shared project. This can then be referenced by a UWP project runner, which can be run on the emulator.
If you take the shared project approach, you can also reference this through an .NET 4.5 project, which will allow your tests to integrate with the NUnit VS adapter, and show up in VS. Portable libraries can not yet be run with this runner, however that's in the pipeline.

Is there any way to do unit tests in Monotouch 4/Monodevelop?

I've tried to write unit tests for my monotouch project without any success. The NUnit dlls are not supported in a Monotouch 4 project.
I've tried some weird workarounds that I've found on some sites but nothing seems to work. These workarounds consist in adding monotouch dll to a Nunit project. This procedure seems to work for others on Monotouch < 4 but it don't work for me (Monotouch > 4). The compiler crashes.
So I was wondering if there are some way to write unit tests into a monotouch project?
Alright, what you can do (this is some serious hoop jumping, and kittens die somewhere when you do this...am I missing something?? If not, please Xamarin, make it easier???):
Create a new MonoTouch iPhone project. Add trivial code.
Create a new C# NUnit project. 3.5 or 4.0, doesnt matter. Add trivial test.
Attempt to add a Project Reference to your NUnit project. Fail. Sigh in frustration.
Build your iPhone project (Release or Debug).
Add a reference (oh god, here it comes) to the output of your iPhone project. Yep, point it to the actual resultant, built iPhone dll. Notice how MonoDevelop allows the reference?
Run your tests. You will be pretty constrained on what you can test, but as long as you are not using MonoTouch classes in your target code you may get away with it.
If I get time I will throw a quick example up on GitHub.
This was attempted using:
MonoTouch 4.0.5
Mono 2.10.4
MonoDevelop 2.6 Beta 3
Make sure that your NUnit project's target framework version is .NET 4.

Categories

Resources