简体   繁体   中英

Unit Testing Monotouch under Visual Studio

I have a Monotouch iOS application that I'm writing in Visual Studio using Xamarin's new Visual-Studio plug-in.

I would like a way to execute my Unit tests from within Visual Studio (eg with the Resharper runner).

I don't much care which unit testing tool I used (they're currently written as nUnit tests).

I know Xamarin supports Touch.Unit which will allow me to run on the device or simulator, but this is too long of a cycle-time, I need it to run on my windows machine.

I tried to use NUnitLite, but this still has the problem of not being able to run on the windows machine.

I also attempted to use the Visual Studio Solution configurations, which should, theoretically allow me to choose a different build configuration in the drop-down to switch between windows (for my cross-platform core library + its tests) and Monotouch (for the IOS UI app, cross-platform library, and IOS tests), but in this, the project references didn't automatically switch to the other framework, or I just messed up how to properly setup a secondary build configuration.

Finally, using two different solution files and separate sets of project files is not ideal because one needs to switch and also keep the clone project's files in sync.

Any ideas on the best way to accomplish easy, fast, unit testing?

The way I've made this work in the past is:

  1. Have all your core code in a regular .Net 4 library. This library has no dependencies on iOS or Android.
  2. Write tests against the core library in another .Net 4 project, using NUnit Lite syntax in your asserts. Use ReSharper to run them all you like.
  3. If you wish, setup an iOS project to run the tests in a simulator - link-in all the files for the tests

On iOS or Android, you will need to link-in the files from the core project.

If you have any platform-specific code in your tests, you won't be able to run them with ReSharper.

If you want to see an example, we took this same approach with Xamarin's Field Service app .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM