.Net Unit Test Runner for iOS

.NET Unit test runner for iOS

As promised here's my own solution for my problem :-) I hope it can help other people too!

EDIT

Sounds like you'd have to write a MonoDevelop add-in that serves up an API for remote NUnit runners to send data to. Not really a trivial task.

The original Touch.Unit was updated to include support for network logging (albeit not inside MonoDevelop).

EDIT #2 : A similar runner now exists for Mono for Android.

FINAL EDIT: Touch.Unit is now an integreal part of MonoTouch releases (starting with version 5.2) and does not have to be downloaded seperately.

How to run MonoTouch unit tests in MonoDevelop?


is there a way to run tests through MonoDevelop like the normal nunit project?

Depending on your unit tests you might still continue to use the normal Unit Test projects. They will be executed by the MonoDevelop's test runner which runs under the normal/desktop .NET runtime (e.g. Mono) under the host operating system (e.g. OSX).

So if you have pure C# test code that does not depend on anything iOS specific then this option is always available.

In contrast MonoTouch Unit Tests Project are meant to be executed using the Touch.Unit test runner under iOS (simulator or devices). As such it must be an application since it is not possible (i.e. allowed under iOS) for a general runner (or any other) application to download and execute code (e.g. a library containing your tests).

Other than the runner the projects are basically just a reference to a NUnitLite (0.6) assembly to give you a unit testing framework.

Since most of my tests don't test the UI

Touch.Unit is not meant to run UI tests - just like NUnit (with it's GUI runner) was not meant to unit test System.Windows.Forms applications. The fact that it provides an UI makes it harder to test (some) UI components.

Touch.Unit's main goal is to allow you to run your test under the same conditions (e.g. CPU, memory) and limitations (e.g. AOT) that a real iOS device (or, to a lesser extent, the iOS simulator) would have - while giving you access to every iOS specific API (supported by the device or the simulator).

Unit testing with UIWebView

Apparently this only happens when unit testing a static library directly. Most likely whatever UIWebView needs is not loaded with an empty test host.

When unit testing an app this doest not occur.

Excluding unit tests only on specific platform

Can you not use traits to achieve this?

ie add a trait which specifies that the tests shouldn't be run on windows then you can execute only tests which don't have this trait in visual studio using whatever test runner you are using.

Testing a Monotouch app with NUnit in MonoDevelop 2.4

In case you missed it, there is now a NUnitLite runner available for MonoTouch which is designed to work for UI agnostic code and executed on devices (or simulator).

See: .NET Unit test runner for iOS

What is the operating principle of IOS Unit Testing Bundle in Xcode 10?

I'm writing a book that describes this. Basically, when you run tests against an iOS app:

  1. Xcode builds the test bundle. Since the tests are dependent on the app, it first builds the app.
  2. It launches the app.
  3. It injects the test bundle into the running app.
  4. It tells the test runner to start.

Xamarin Unit Testing from the Command Line

The most popular unit testing frameworks used with Xamarin are NUnit and XUnit. They are both similar to JUnit.

  1. Usually a Xamarin cross-platform app uses a Portable Class Library (PCL) project where the platform agnostic (shared) code sits: business logic, model, view models, service etc. This code is unit tested in a seperate pcl or.net45 test project which references the source project and nunit/xunit.

To run the nunit/xunit unit tests you need to run the corresponding test runner and point it tou your test assembly. Both nunit and xundit feature console runners which can be parameterized at will from your command line (see links).

Feel free to chose either nunit or xunit. I like them both.


  1. You might also have platform specific unit tests (which depend on the android/ios/uwp sdks) and that have to be run on a device. These tests can also be created with nunit or xunit and run with nunit device runner or xunit device runner. Basically what will happen here is you add an android/ios app project for testing which references nunit/junit, contains your device specific tests and links to your shared tests and can run them both on the device.

  2. There is also the layer of coded UI tests where NUnit, Xamarin UITest and Specflow might be of use. Im guessing this part is beyond the scope of your question.

But then again you are coming form Android and are used with gradle. Well Xamarin and .net does not have gradle but it has Cake. I use it to automate all my project builds/tests/ci/deployments etc.

Cake (C# Make) is a cross platform build automation system with a C# DSL to do things like compiling code, copy files/folders, running unit tests, compress files and build NuGet packages.

Your Cake script can look something like this:

Task("Run-Unit-Tests")
.IsDependentOn("Build")
.Does(() =>
{
NUnit("./src/**/bin/" + configuration + "/*.Tests.dll");
});

Task("Build")
.Does(() =>
{
DotNetBuild("YourAndroid.csproj");
DotNetBuild("YourCoreTests.csproj");
...
}
);

Cake comes with a bootstrapper file either (ps1 - powershell for windows or sh for mac) which downloads all the tools you need to run your script (cake itself, nuget, nunit/xunit runner etc).

Your command line/CI can run it like this:

./build.sh -Target Run-Unit-Tests


Related Topics



Leave a reply



Submit