From 1afaec0b1e74898ee42bb052248390e2ca995ffd Mon Sep 17 00:00:00 2001 From: Rob Prouse Date: Mon, 16 Nov 2015 22:25:32 -0500 Subject: [PATCH 1/6] Minor fixes while testing --- .../uap10.0/MainPage.xaml.cs.txt.pp | 0 .../nunit.runner.tests.Droid/nunit.runner.tests.Droid.csproj | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) rename MainPage.xaml.cs.txt.pp => nuget/uap10.0/MainPage.xaml.cs.txt.pp (100%) diff --git a/MainPage.xaml.cs.txt.pp b/nuget/uap10.0/MainPage.xaml.cs.txt.pp similarity index 100% rename from MainPage.xaml.cs.txt.pp rename to nuget/uap10.0/MainPage.xaml.cs.txt.pp diff --git a/src/tests/nunit.runner.tests.Droid/nunit.runner.tests.Droid.csproj b/src/tests/nunit.runner.tests.Droid/nunit.runner.tests.Droid.csproj index 013ab8d..7a720ff 100644 --- a/src/tests/nunit.runner.tests.Droid/nunit.runner.tests.Droid.csproj +++ b/src/tests/nunit.runner.tests.Droid/nunit.runner.tests.Droid.csproj @@ -100,7 +100,7 @@ - + From fdb08b210d25ae060d92ea92925453c016cb4d05 Mon Sep 17 00:00:00 2001 From: Rob Prouse Date: Tue, 17 Nov 2015 17:40:56 -0500 Subject: [PATCH 2/6] Removed Windows 10 from the nuget package --- nuget/nunit.runners.xamarin.nuspec | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/nuget/nunit.runners.xamarin.nuspec b/nuget/nunit.runners.xamarin.nuspec index 43293c4..c2d5c3d 100644 --- a/nuget/nunit.runners.xamarin.nuspec +++ b/nuget/nunit.runners.xamarin.nuspec @@ -1,7 +1,7 @@ - nunit.runner.xamarin + nunit.xamarin $version$ NUnit 3.0 Xamarin Runner Rob Prouse @@ -11,10 +11,9 @@ Supported Xamarin platforms: - Android - iOS - - Windows Phone 8.1 - - Windows 10 Universal + - Windows Phone 8.1 NUnit 3.0 runner components for Xamarin - nunit xamarin android ios monoandroid monotouch winphone uwp tdd unit test testing + nunit xamarin android ios monoandroid monotouch winphone tdd unit test testing en-US http://nunit.org/nuget/nunit3-license.txt https://github.com/nunit/nunit.xamarin @@ -41,9 +40,5 @@ Supported Xamarin platforms: - - - - From a92108977862454e863576d955a16ab947bdc8a5 Mon Sep 17 00:00:00 2001 From: Rob Prouse Date: Tue, 17 Nov 2015 20:28:06 -0500 Subject: [PATCH 3/6] Ready to release for Android, iOS and WinPhone --- README.md | 167 +++++++++++++++++++++++------ build.cake | 1 - nuget/nunit.runners.xamarin.nuspec | 15 +-- nuget/wpa81/MainPage.xaml.txt.pp | 14 +++ nunit.runner.sln | 1 + 5 files changed, 155 insertions(+), 43 deletions(-) create mode 100644 nuget/wpa81/MainPage.xaml.txt.pp diff --git a/README.md b/README.md index 20a9011..53db20a 100644 --- a/README.md +++ b/README.md @@ -4,64 +4,161 @@ NUnit test runners for Xamarin and mobile devices ## How to Use ## -The NuGet packages are nearly ready and we will likely create project templates, but until that is done, -you will need to build from source. For this, you will need a Xamarin trial or subscription. +Project templates will be coming soon, in the meantime... -1. Clone this repository -2. Open `nunit.runner.sln` in Visual Studio with Xamarin installed, or in Xamarin Studio. -3. Create a release build of the solution. +In your solution; -Then in your solution; - -1. Add a new `Blank App (Android)` or `Blank App (iOS)` to your solution -2. Add NuGet packages to your project for `NUnit 3.0.0-beta-4` and `Xamarin.Forms 1.4.4.6392` -3. Browse and add a reference to the `nunit.runner.droid.dll` or `nunit.runner.ios.dll` that you built -4. Write your unit tests in this project, or in a shared project -5. Change the base class of `MainActivity` on Android to `global::Xamarin.Forms.Platform.Android.FormsApplicationActivity` -6. Change the base class of `AppDelegate` on iOS to `global::Xamarin.Forms.Platform.iOS.FormsApplicationDelegate` -7. Change MainActivity.OnCreate() on Android or AppDelegate.FinishedLaunching() on iOS -8. Build and run the tests on your device or emulator +1. Add a new `Blank App (Android)`, `Blank App (iOS)` and/or `Blank App (Windows Phone)` project to your solution +2. Add the `nunit.xamarin` NuGet package to your projects +3. Text files will be added to your project, open them and copy over the coresponding file in each project as appropriate. + - `MainActivity.cs.txt` for Android, + - `AppDelegate.cs.txt` for iOS, or + - `MainPage.xaml.txt` and `MainPage.xaml.cs.txt` for WinPhone. +4. Once you are done with them, you can delete the text files that were added to your project. +5. On Windows Phone, you will also need to add `Xamarin.Forms.Forms.Init(e);` to `App.OnLaunched()`. +6. Write your unit tests in this project, or in a shared project +7. Build and run the tests on your device or emulator ### Android ### +**MainActivity.cs** + ```C# -protected override void OnCreate(Bundle savedInstanceState) +[Activity(Label = "NUnit 3.0", MainLauncher = true, Theme = "@android:style/Theme.Holo.Light", ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)] +public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsApplicationActivity { - base.OnCreate(savedInstanceState); + protected override void OnCreate(Bundle savedInstanceState) + { + base.OnCreate(savedInstanceState); - global::Xamarin.Forms.Forms.Init(this, savedInstanceState); + global::Xamarin.Forms.Forms.Init(this, savedInstanceState); - // This will load all tests within the current project - var nunit = new NUnit.Runner.App(); + // This will load all tests within the current project + var nunit = new NUnit.Runner.App(); - // If you want to add tests in another assembly - //nunit.AddTestAssembly(typof(MyTests).Assembly); + // If you want to add tests in another assembly + //nunit.AddTestAssembly(typeof(MyTests).Assembly); - // Do you want to automatically run tests when the app starts? - nunit.AutoRun = true; + // Do you want to automatically run tests when the app starts? + nunit.AutoRun = true; - LoadApplication(nunit); + LoadApplication(nunit); + } } ``` ### iOS ### +**AppDelegate.cs** + ```C# -public override bool FinishedLaunching(UIApplication app, NSDictionary options) +[Register("AppDelegate")] +public partial class AppDelegate : global::Xamarin.Forms.Platform.iOS.FormsApplicationDelegate { - global::Xamarin.Forms.Forms.Init(); + // + // This method is invoked when the application has loaded and is ready to run. In this + // method you should instantiate the window, load the UI into it and then make the window + // visible. + // + // You have 17 seconds to return from this method, or iOS will terminate your application. + // + public override bool FinishedLaunching(UIApplication app, NSDictionary options) + { + global::Xamarin.Forms.Forms.Init(); + + // This will load all tests within the current project + var nunit = new NUnit.Runner.App(); + + // If you want to add tests in another assembly + //nunit.AddTestAssembly(typeof(MyTests).Assembly); + + // Do you want to automatically run tests when the app starts? + nunit.AutoRun = true; + + LoadApplication(nunit); + + return base.FinishedLaunching(app, options); + } +} +``` + +### Windows Phone 8.1 ### + +**MainPage.xaml** - // This will load all tests within the current project - var nunit = new NUnit.Runner.App(); +```XML + - // If you want to add tests in another assembly - //nunit.AddTestAssembly(typof(MyTests).Assembly); + + + + +``` + +**MainPage.xaml.cs** + +```C# +public sealed partial class MainPage : WindowsPhonePage +{ + public MainPage() + { + InitializeComponent(); - // Do you want to automatically run tests when the app starts? - nunit.AutoRun = true; + // Windows Phone will not load all tests within the current project, + // you must do it explicitly below + var nunit = new NUnit.Runner.App(); - LoadApplication(nunit); + // If you want to add tests in another assembly, add a reference and + // duplicate the following line with a type from the referenced assembly + nunit.AddTestAssembly(typeof(MainPage).GetTypeInfo().Assembly); - return base.FinishedLaunching(app, options); + // Do you want to automatically run tests when the app starts? + nunit.AutoRun = true; + + LoadApplication(nunit); + + this.NavigationCacheMode = NavigationCacheMode.Required; + } } ``` +**App.xaml.cs** + +```C# +protected override void OnLaunched(LaunchActivatedEventArgs e) +{ + Frame rootFrame = Window.Current.Content as Frame; + + // Do not repeat app initialization when the Window already has content, + // just ensure that the window is active + if (rootFrame == null) + { + // Create a Frame to act as the navigation context and navigate to the first page + rootFrame = new Frame(); + + // TODO: change this value to a cache size that is appropriate for your application + rootFrame.CacheSize = 1; + + // Set the default language + rootFrame.Language = Windows.Globalization.ApplicationLanguages.Languages[0]; + + // ==> ADD THIS LINE <== + Xamarin.Forms.Forms.Init(e); + + if (e.PreviousExecutionState == ApplicationExecutionState.Terminated) + { + // TODO: Load state from previously suspended application + } + + // Place the frame in the current Window + Window.Current.Content = rootFrame; + } +} +``` \ No newline at end of file diff --git a/build.cake b/build.cake index 50b0291..5af02e8 100644 --- a/build.cake +++ b/build.cake @@ -52,7 +52,6 @@ Task("Clean") }); Task("Restore-NuGet-Packages") - .IsDependentOn("Clean") .Does(() => { NuGetRestore("./nunit.runner.sln", new NuGetRestoreSettings { diff --git a/nuget/nunit.runners.xamarin.nuspec b/nuget/nunit.runners.xamarin.nuspec index c2d5c3d..df82a33 100644 --- a/nuget/nunit.runners.xamarin.nuspec +++ b/nuget/nunit.runners.xamarin.nuspec @@ -24,19 +24,20 @@ Supported Xamarin platforms: - + - - - + + + - - - + + + + diff --git a/nuget/wpa81/MainPage.xaml.txt.pp b/nuget/wpa81/MainPage.xaml.txt.pp new file mode 100644 index 0000000..f3c7c7a --- /dev/null +++ b/nuget/wpa81/MainPage.xaml.txt.pp @@ -0,0 +1,14 @@ + + + + + + diff --git a/nunit.runner.sln b/nunit.runner.sln index 83a8182..e80ab9d 100644 --- a/nunit.runner.sln +++ b/nunit.runner.sln @@ -53,6 +53,7 @@ EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "wpa81", "wpa81", "{20C1F6F6-6CA3-4C75-9058-90A8CDABCEE9}" ProjectSection(SolutionItems) = preProject nuget\wpa81\MainPage.xaml.cs.txt.pp = nuget\wpa81\MainPage.xaml.cs.txt.pp + nuget\wpa81\MainPage.xaml.txt.pp = nuget\wpa81\MainPage.xaml.txt.pp EndProjectSection EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Xamarin.iOS10", "Xamarin.iOS10", "{30BB9B64-B2B7-4F09-BF00-D4C76849A540}" From e71a1331cf11ee4d880a44a3b68797a866f86457 Mon Sep 17 00:00:00 2001 From: Rob Prouse Date: Tue, 17 Nov 2015 20:30:25 -0500 Subject: [PATCH 4/6] Updated the README --- README.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 53db20a..8e29907 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,10 @@ Project templates will be coming soon, in the meantime... In your solution; -1. Add a new `Blank App (Android)`, `Blank App (iOS)` and/or `Blank App (Windows Phone)` project to your solution +1. Add a new project to your solution + - `Blank App (Android)` for Android, + - `Blank App (iOS)` for iOS, + - `Blank App (Windows Phone)` for Windows Phone 8.1 2. Add the `nunit.xamarin` NuGet package to your projects 3. Text files will be added to your project, open them and copy over the coresponding file in each project as appropriate. - `MainActivity.cs.txt` for Android, From 826c7acb37e994b83fe18c6ac960e4523d8215a9 Mon Sep 17 00:00:00 2001 From: Rob Prouse Date: Tue, 17 Nov 2015 20:34:15 -0500 Subject: [PATCH 5/6] Added the Win10 nuget content for later --- nuget/uap10.0/MainPage.xaml.txt.pp | 13 +++++++++++++ nunit.runner.sln | 3 ++- 2 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 nuget/uap10.0/MainPage.xaml.txt.pp diff --git a/nuget/uap10.0/MainPage.xaml.txt.pp b/nuget/uap10.0/MainPage.xaml.txt.pp new file mode 100644 index 0000000..cc61852 --- /dev/null +++ b/nuget/uap10.0/MainPage.xaml.txt.pp @@ -0,0 +1,13 @@ + + + + + + diff --git a/nunit.runner.sln b/nunit.runner.sln index e80ab9d..77f0fba 100644 --- a/nunit.runner.sln +++ b/nunit.runner.sln @@ -47,7 +47,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "MonoAndroid10", "MonoAndroi EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "uap10.0", "uap10.0", "{6B2E96B2-DED0-4541-97CE-416C0C6A38DD}" ProjectSection(SolutionItems) = preProject - MainPage.xaml.cs.txt.pp = MainPage.xaml.cs.txt.pp + nuget\uap10.0\MainPage.xaml.cs.txt.pp = nuget\uap10.0\MainPage.xaml.cs.txt.pp + nuget\uap10.0\MainPage.xaml.txt.pp = nuget\uap10.0\MainPage.xaml.txt.pp EndProjectSection EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "wpa81", "wpa81", "{20C1F6F6-6CA3-4C75-9058-90A8CDABCEE9}" From f294c7d3d11c89f3a9ccb641e1f033c162996623 Mon Sep 17 00:00:00 2001 From: Rob Prouse Date: Tue, 17 Nov 2015 20:53:26 -0500 Subject: [PATCH 6/6] Added Universal Windows support back in - Fixes #28 --- README.md | 92 +++++++++++++++++++++++++++++- nuget/nunit.runners.xamarin.nuspec | 6 +- 2 files changed, 95 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 8e29907..82d99e9 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ NUnit test runners for Xamarin and mobile devices ## How to Use ## -Project templates will be coming soon, in the meantime... +**Project templates will be coming soon**, in the meantime... In your solution; @@ -12,13 +12,15 @@ In your solution; - `Blank App (Android)` for Android, - `Blank App (iOS)` for iOS, - `Blank App (Windows Phone)` for Windows Phone 8.1 + - `Blank App (Universal Windows)` for Windows 10 Universal 2. Add the `nunit.xamarin` NuGet package to your projects 3. Text files will be added to your project, open them and copy over the coresponding file in each project as appropriate. - `MainActivity.cs.txt` for Android, - `AppDelegate.cs.txt` for iOS, or - `MainPage.xaml.txt` and `MainPage.xaml.cs.txt` for WinPhone. + - Windows 10 Universal doesn't currently add files, see below for what to change. 4. Once you are done with them, you can delete the text files that were added to your project. -5. On Windows Phone, you will also need to add `Xamarin.Forms.Forms.Init(e);` to `App.OnLaunched()`. +5. On Windows Phone and Windows Universal, you will also need to add `Xamarin.Forms.Forms.Init(e);` to `App.OnLaunched()`. 6. Write your unit tests in this project, or in a shared project 7. Build and run the tests on your device or emulator @@ -137,6 +139,8 @@ public sealed partial class MainPage : WindowsPhonePage ```C# protected override void OnLaunched(LaunchActivatedEventArgs e) { + // + Frame rootFrame = Window.Current.Content as Frame; // Do not repeat app initialization when the Window already has content, @@ -163,5 +167,89 @@ protected override void OnLaunched(LaunchActivatedEventArgs e) // Place the frame in the current Window Window.Current.Content = rootFrame; } + + // +} +``` + + + +### Windows 10 Universal ### + +**MainPage.xaml** + +```XML + + + + + + +``` + +**MainPage.xaml.cs** + +```C# +public sealed partial class MainPage : WindowsPage +{ + public MainPage() + { + InitializeComponent(); + + // Windows Universal will not load all tests within the current project, + // you must do it explicitly below + var nunit = new NUnit.Runner.App(); + + // If you want to add tests in another assembly, add a reference and + // duplicate the following line with a type from the referenced assembly + nunit.AddTestAssembly(typeof(MainPage).GetTypeInfo().Assembly); + + // Do you want to automatically run tests when the app starts? + nunit.AutoRun = true; + + LoadApplication(nunit); + } +} +``` + +**App.xaml.cs** + +```C# +protected override void OnLaunched(LaunchActivatedEventArgs e) +{ + // + + Frame rootFrame = Window.Current.Content as Frame; + + // Do not repeat app initialization when the Window already has content, + // just ensure that the window is active + if (rootFrame == null) + { + // Create a Frame to act as the navigation context and navigate to the first page + rootFrame = new Frame(); + + rootFrame.NavigationFailed += OnNavigationFailed; + + // ==> ADD THIS LINE <== + Xamarin.Forms.Forms.Init(e); + + if (e.PreviousExecutionState == ApplicationExecutionState.Terminated) + { + // TODO: Load state from previously suspended application + } + + // Place the frame in the current Window + Window.Current.Content = rootFrame; + } + + // } ``` \ No newline at end of file diff --git a/nuget/nunit.runners.xamarin.nuspec b/nuget/nunit.runners.xamarin.nuspec index df82a33..c48593e 100644 --- a/nuget/nunit.runners.xamarin.nuspec +++ b/nuget/nunit.runners.xamarin.nuspec @@ -11,7 +11,8 @@ Supported Xamarin platforms: - Android - iOS - - Windows Phone 8.1 + - Windows Phone 8.1 + - Windows 10 Universal Apps NUnit 3.0 runner components for Xamarin nunit xamarin android ios monoandroid monotouch winphone tdd unit test testing en-US @@ -41,5 +42,8 @@ Supported Xamarin platforms: + + +