diff --git a/README.md b/README.md index 20a9011..82d99e9 100644 --- a/README.md +++ b/README.md @@ -4,64 +4,252 @@ 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... + +In 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 + - `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 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 -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. +### Android ### -Then in your solution; +**MainActivity.cs** -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 +```C# +[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 +{ + protected override void OnCreate(Bundle savedInstanceState) + { + base.OnCreate(savedInstanceState); -### Android ### + global::Xamarin.Forms.Forms.Init(this, savedInstanceState); + + // 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); + } +} +``` +### iOS ### + +**AppDelegate.cs** ```C# -protected override void OnCreate(Bundle savedInstanceState) +[Register("AppDelegate")] +public partial class AppDelegate : global::Xamarin.Forms.Platform.iOS.FormsApplicationDelegate { - base.OnCreate(savedInstanceState); + // + // 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); + } +} +``` - global::Xamarin.Forms.Forms.Init(this, savedInstanceState); +### Windows Phone 8.1 ### - // This will load all tests within the current project - var nunit = new NUnit.Runner.App(); +**MainPage.xaml** - // If you want to add tests in another assembly - //nunit.AddTestAssembly(typof(MyTests).Assembly); +```XML + - // Do you want to automatically run tests when the app starts? - nunit.AutoRun = true; + - LoadApplication(nunit); + + +``` + +**MainPage.xaml.cs** + +```C# +public sealed partial class MainPage : WindowsPhonePage +{ + public MainPage() + { + InitializeComponent(); + + // Windows Phone 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); + + this.NavigationCacheMode = NavigationCacheMode.Required; + } } ``` -### iOS ### + +**App.xaml.cs** ```C# -public override bool FinishedLaunching(UIApplication app, NSDictionary options) +protected override void OnLaunched(LaunchActivatedEventArgs e) { - global::Xamarin.Forms.Forms.Init(); + // + + 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; - // This will load all tests within the current project - var nunit = new NUnit.Runner.App(); + // Set the default language + rootFrame.Language = Windows.Globalization.ApplicationLanguages.Languages[0]; - // If you want to add tests in another assembly - //nunit.AddTestAssembly(typof(MyTests).Assembly); + // ==> ADD THIS LINE <== + Xamarin.Forms.Forms.Init(e); - // Do you want to automatically run tests when the app starts? - nunit.AutoRun = true; + if (e.PreviousExecutionState == ApplicationExecutionState.Terminated) + { + // TODO: Load state from previously suspended application + } - LoadApplication(nunit); + // Place the frame in the current Window + Window.Current.Content = rootFrame; + } - return base.FinishedLaunching(app, options); + // } ``` + + +### 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/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 43293c4..c48593e 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 @@ -12,9 +12,9 @@ Supported Xamarin platforms: - Android - iOS - Windows Phone 8.1 - - Windows 10 Universal + - Windows 10 Universal Apps 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 @@ -25,24 +25,24 @@ Supported Xamarin platforms: - + - - - + + + - - - + + + + - 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/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/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..77f0fba 100644 --- a/nunit.runner.sln +++ b/nunit.runner.sln @@ -47,12 +47,14 @@ 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}" 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}" 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 @@ - +