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.
Related
I am using VS2019 Professional to develop a Xamarin.Forms app. The project solution consists of the typical head projects which deploy to specific platforms, and the common cross-platform project that contains the bulk of the solution's code. I am trying to find some way, if possible, to run performance tests on the common cross-platform project, which builds to a .NET Standard DLL.
Xamarin currently does not have any tooling available to profile the platform-specific app using the DLL, so I need to find some other way. I have unit tests for this DLL, but there doesn't seem to be any support for profiling unit tests in VS2019. I have tried profiling the vstest.console application that runs the unit tests that test my DLL, but the only option available is to instrument vstest.console, which will do me no good either (obviously don't want to go mucking around with the guts of the test runner!). At this point it seems the only option is to develop an additional test console application and profile that, but I just wanted to check if anyone has encountered a similar use case and found a more elegant solution?
I'm trying to use xbuild from mono to compile my C# web application. I keep running into this error:
Field 'System.Text.RegularExpressions.Regex.IsMatch' not found.
The only thing that I've been able to find about this error is to add 'System' as an assembly reference in the csproj file which I already had there. I also tried installing the 'System.Text.RegularExpressions' NuGet package and putting an assembly reference of 'System.Text.RegularExpressions' in the csproj file. Neither of those worked.
One thing I should note here. This error only gets thrown in my test library. I can build everything else fine without the tests but I need to be able to build the tests as I'm trying to set up CI that runs the tests. The tests are using NUnit.
Here's the data for what I'm using:
XBuild Engine Version 14.0
Mono, Version 4.8.0.0
C# 6
.NET Framework 4.5.2 (but have tried building with 4.5.0, 4.0.0, and 4.3.0)
I figured out what this problem was. We were using Selenium for UI tests and the drivers for that were preventing the build from completing for some reason. As far as what part in Selenium was causing this, I'm not sure.
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.
I'm just looking for a definitive answer on this: are there any mocking frameworks that work with Mono, like Moq or RhinoMocks??? Yes, I realize I can do manual mocks, but I'm talking about something with a nice API...like Moq or RhinoMocks. I'm working with MonoTouch specifically, but I'm surprised I haven't even been able to find any mocking frameworks for straight Mono either.
From what I've read, it seems that one of the reasons why there's no mocking framework for MonoTouch is because most of them use Reflection.Emit, which will of course not pass Apple's static analysis for AppStore submission.
BUT, what about non-AppStore apps? Lots of enterprise apps are distributed outside of the AppStore and so are not subject to the static analysis. AND it's very common to see mocking frameworks used in enterprise apps.
So, why don't we see mocking frameworks being used more frequently with MonoTouch apps?
Well, I found that the Moq source from GitHub CAN be compiled for Mono. But you also need Castle.Core.
However, you try to build Castle.Core with Mono 2.10.x (2.10.11 at the time of this writing), you'll get a compile error (CS0314) about generic type constraints in PriorityBehaviorExtensions.cs. This is a bug in the 2.10.x builds of Mono.
In order to build Castle.Core, I had to build with Mono 3.0.10. Once you have that dependency satisfied, you can use Castle.Core to build Moq.
I still have to do some testing to make sure all is well. Just wanted to get this all written up before I head out the door. Hope this helps someone.
Thanks to the author of Moq (Daniel Cazzulino) for pointing me in the right direction.
EDIT: This is NOT working for me. I was able to build the DLLs just fine, but they were targeting the wrong framework. The problem is that I can't seem to build the Castle.Core library targeting MonoTouch because some of the functionality of .NET that Castle.Core takes advantage of is simply not available in Mono. SO, without being able to build Castle.Core for MonoTouch, I also cannot build Moq or even RhinoMocks for MonoTouch either.
I've found that Simple.Mocking works out of the box with Mono. It isn't quite as neat as some of the other mocking frameworks out there but it does work!
I'm asking this question due to Silverlight and NUnit, that if you've tried, know they do not play well together. Basic reason being SL code is compiled against the SL framework, and NUnit is compiled against the standard .NET framework.
Anyway, I've got a bunch of classes that are not specific to SL but do reside on the client side. I was thinking about moving them into their own library. Is it possible to configure Visual Studio and/or solution to compile this library both as an SL library AND a .NET library?
My SL client app would reference the SL-version of the library, NUnit would reference the .NET-version.
I'm suspecting at best, this would have to somehow be arranged through the makefile, and the NUnit test project could not reference the project directly, but rather the .dll created.
And other issues like that.
Just wondering what peoples thoughts are on this idea.
Like you were planning to do, you could create SL Class libaray and .Net Class library and have the code in one project and do file link in the other project. This way you do not need to keep two copies of the files. So you can point to the .net class library for the NUnit tests. Just a thought.
Sounds like a job for Portable Class Libraries VS 2012 has built in support and there is an add-on for 2010.