Bug 8687 - Unit Tests hang on real iPhone
Summary: Unit Tests hang on real iPhone
Status: RESOLVED INVALID
Alias: None
Product: iOS
Classification: Xamarin
Component: General ()
Version: 6.0.x
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2012-11-30 05:02 UTC by BB
Modified: 2012-12-04 07:59 UTC (History)
2 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:


Attachments
Source code for EmptyProject (13.58 KB, application/zip)
2012-11-30 06:54 UTC, BB
Details


Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED INVALID

Description BB 2012-11-30 05:02:27 UTC
Hi,

I have a problem running Unit Tests (using Nunit) on a real iPhone (works fine on Simulator).

Here is how to reproduce the problem (I'm using MonoDevelop 3.0.5 and MonoTouch 6.0.6) - CODE IS ALSO ATTACHED:

1) Create a new empty MonoTouch project (single View, universal app), called "EmptyProject"

2) Following these instructions: http://docs.xamarin.com/ios/Guides/Deployment%252c_Testing%252c_and_Metrics/Touch.Unit
Add a MonoTouch Unit Tests Project, called "UnitTests".

3) Add a default new UnitTests file (with Pass, Fail, Ignore examples), called "Test1.cs"

4) Run this on the simulator and on a real iPhone and it works OK on both at this stage.

5) Now, in EmptyProject, add a method that can easily be called, eg in EmptyProjectViewController, add:

 public static void Hello() 
    {
      Console.WriteLine("HELLO");
    }

7) In the UnitTests project, add a reference to EmptyProject (Edit References > Projects tab > tick EmptyProject

8) In Test1.cs add a call to Hello:

    using EmptyProject;

    [Test]
    public void Pass()
    {
      EmptyProjectViewController.Hello();
      Assert.True(true);
    }

9) Now compile both EmptyProject and UnitTests

10) Run UnitTests on the simulator - all runs OK - outputs HELLO in console OK.

11) Run UnitTests on a real iPhone - it HANGS (ive tried iPhone iOS 5.1 and iPod Touch iOS 6.0 devices, they both hang).

The output is:
Please ensure your device is connected...
Connected to: Bill’s O2 iPhone
Launching /private/var/mobile/Applications/61757B02-6486-4837-96B6-74744B051C71/UnitTests.app -debugtrack -monodevelop-port 10000 -connection-mode usb
Loaded assembly: /private/var/mobile/Applications/61757B02-6486-4837-96B6-74744B051C71/UnitTests.app/Mono.Security.dll [External]
Loaded assembly: /private/var/mobile/Applications/61757B02-6486-4837-96B6-74744B051C71/UnitTests.app/System.dll [External]
Loaded assembly: /private/var/mobile/Applications/61757B02-6486-4837-96B6-74744B051C71/UnitTests.app/System.Core.dll [External]
Loaded assembly: /private/var/mobile/Applications/61757B02-6486-4837-96B6-74744B051C71/UnitTests.app/monotouch.dll [External]
Loaded assembly: /private/var/mobile/Applications/61757B02-6486-4837-96B6-74744B051C71/UnitTests.app/System.Json.dll [External]
Loaded assembly: /private/var/mobile/Applications/61757B02-6486-4837-96B6-74744B051C71/UnitTests.app/MonoTouch.Dialog-1.dll [External]
Loaded assembly: /private/var/mobile/Applications/61757B02-6486-4837-96B6-74744B051C71/UnitTests.app/MonoTouch.NUnitLite.dll [External]
Loaded assembly: /private/var/mobile/Applications/61757B02-6486-4837-96B6-74744B051C71/UnitTests.app/EmptyProject.exe
Loaded assembly: /private/var/mobile/Applications/61757B02-6486-4837-96B6-74744B051C71/UnitTests.app/UnitTests.exe
Thread started: Finalizer

and the iPhone just shows a blank screen with the status bar at the top.

Please let me know what the problem is.
Comment 1 BB 2012-11-30 05:08:43 UTC
I tried add the code as a ZIP of the project but it was too big (19Mbytes), but it's easy to reproduce from above anyway.
Comment 2 Rolf Bjarne Kvinge [MSFT] 2012-11-30 06:49:31 UTC
If you remove the bin and obj directories in the project directory, it should zip up to a lot less than 19 MB.
Comment 3 BB 2012-11-30 06:54:55 UTC
Created attachment 3032 [details]
Source code for EmptyProject
Comment 4 BB 2012-11-30 06:56:43 UTC
Thanks, now attached.
Comment 5 Rolf Bjarne Kvinge [MSFT] 2012-11-30 07:09:59 UTC
It's because there are two AppDelegate classes, each registered as "AppDelegate" to ObjectiveC.

At runtime it's completely random which one is picked. Comment out the [Register ("AppDelegate")] line in EmptyProject's AppDelegate.cs, and the NUnit UI shows up just fine.
Comment 6 BB 2012-11-30 07:35:34 UTC
Ah yes, thanks, that's the problem.  I've changed the register name to 

[Register ("TestAppDelegate")]

and in Main.cs:

UIApplication.Main(args, null, "TestAppDelegate");

and then all works OK.

It would be good if you could change the default setup to be something like this when someone adds a Unit Test project - or surely everyone will hit this problem?
Comment 7 Rolf Bjarne Kvinge [MSFT] 2012-12-04 07:59:07 UTC
I've changed the default app delegate to "UnitTestAppDelegate" for test projects to avoid this problem in the future.