Jean-Philippe Leclerc
Jean-Philippe Leclerc

Reputation: 6805

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?

Upvotes: 1

Views: 212

Answers (2)

Ben Phegan
Ben Phegan

Reputation: 535

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???):

  1. Create a new MonoTouch iPhone project. Add trivial code.
  2. Create a new C# NUnit project. 3.5 or 4.0, doesnt matter. Add trivial test.
  3. Attempt to add a Project Reference to your NUnit project. Fail. Sigh in frustration.
  4. Build your iPhone project (Release or Debug).
  5. 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?
  6. 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

Upvotes: 1

Mikayla Hutchinson
Mikayla Hutchinson

Reputation: 16153

Make sure that your NUnit project's target framework version is .NET 4.

Upvotes: 0

Related Questions