Have you noticed that:
- MonoTouch 5.1 (beta) is out ?
- MonoTouch.Dialog.dll is bundled within ??
- MonoTouch.NUnitLite.dll is also part of the package ???
What’s that ? It’s Touch.Unit main assembly, i.e. where the runner logic, UI and NUnitLite code resides. So it means you’ll get a unit test framework included with MonoTouch – almost no extra steps required.
Here are some quick instructions to get you going:
- Start MonoDevelop
- Create a new solution / project, e.g. Universal template, Empty Project and name it AppUnitTest;
- Add a reference to: /Developer/MonoTouch/usr/lib/mono/2.1/MonoTouch.NUnitLite.dll
- Open your AppDelegate.cs file and replace its content with:
- Create a new (empty C#) file, e.g. RegressionTest.cs, and paste the following code to replace its content:
- Build and execute
using MonoTouch.Foundation; using MonoTouch.UIKit; using MonoTouch.NUnit.UI; namespace AppUnitTests { [Register ("AppDelegate")] public partial class AppDelegate : UIApplicationDelegate { // class-level declarations UIWindow window; TouchRunner runner; public override bool FinishedLaunching (UIApplication app, NSDictionary options) { window = new UIWindow (UIScreen.MainScreen.Bounds); runner = new TouchRunner (window); // register every tests included in the main application/assembly runner.Add (System.Reflection.Assembly.GetExecutingAssembly ()); window.RootViewController = new UINavigationController (runner.GetViewController ()); window.MakeKeyAndVisible (); return true; } } }
using System; using NUnit.Framework; namespace Fixtures { [TestFixture] public class Tests { [Test] public void Pass () { Assert.True (true); } [Test] public void Fail () { Assert.False (true); } [Test] [Ignore ("another time")] public void Ignore () { Assert.True (false); } } }
Can it get better ? Yep! Once the next release of MonoDevelop becomes available you’ll have templates to create a unit test project and unit test fixtures (files).