Touch.Unit getting closer to you

Have you noticed that:

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:

  1. Start MonoDevelop
  2. Create a new solution / project, e.g. Universal template, Empty Project and name it AppUnitTest;
  3. Add a reference to: /Developer/MonoTouch/usr/lib/mono/2.1/MonoTouch.NUnitLite.dll
  4. Open your AppDelegate.cs file and replace its content with:
  5. 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;
    		}
    	}
    }
    
  6. Create a new (empty C#) file, e.g. RegressionTest.cs, and paste the following code to replace its content:
  7. 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);
    		}
    	}
    }
    
  8. Build and execute

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).

Advertisements

About spouliot

Xamarin Hacker, Mono Contributor, Open Source Enthusiast with strong interests in Code Analysis, Cryptography and Security. Presently working on MonoTouch, previous projects were Moonlight and libgdiplus and a lot of the cryptographic work done on Mono.
This entry was posted in mono, monotouch, touch.unit, xamarin. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s