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 workaroun开发者_运维问答ds 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.
精彩评论