@@ -4,21 +4,23 @@ NUnit test runners for Xamarin and mobile devices
44
55## How to Use ##
66
7- Project templates will be coming soon, in the meantime...
7+ ** Project templates will be coming soon** , in the meantime...
88
99In your solution;
1010
11111 . Add a new project to your solution
1212 - ` Blank App (Android) ` for Android,
1313 - ` Blank App (iOS) ` for iOS,
1414 - ` Blank App (Windows Phone) ` for Windows Phone 8.1
15+ - ` Blank App (Universal Windows) ` for Windows 10 Universal
15162 . Add the ` nunit.xamarin ` NuGet package to your projects
16173 . Text files will be added to your project, open them and copy over the coresponding file in each project as appropriate.
1718 - ` MainActivity.cs.txt ` for Android,
1819 - ` AppDelegate.cs.txt ` for iOS, or
1920 - ` MainPage.xaml.txt ` and ` MainPage.xaml.cs.txt ` for WinPhone.
21+ - Windows 10 Universal doesn't currently add files, see below for what to change.
20224 . Once you are done with them, you can delete the text files that were added to your project.
21- 5 . On Windows Phone, you will also need to add ` Xamarin.Forms.Forms.Init(e); ` to ` App.OnLaunched() ` .
23+ 5 . On Windows Phone and Windows Universal , you will also need to add ` Xamarin.Forms.Forms.Init(e); ` to ` App.OnLaunched() ` .
22246 . Write your unit tests in this project, or in a shared project
23257 . Build and run the tests on your device or emulator
2426
@@ -137,6 +139,8 @@ public sealed partial class MainPage : WindowsPhonePage
137139``` C#
138140protected override void OnLaunched (LaunchActivatedEventArgs e )
139141{
142+ // <SNIP>
143+
140144 Frame rootFrame = Window .Current .Content as Frame ;
141145
142146 // Do not repeat app initialization when the Window already has content,
@@ -163,5 +167,89 @@ protected override void OnLaunched(LaunchActivatedEventArgs e)
163167 // Place the frame in the current Window
164168 Window .Current .Content = rootFrame ;
165169 }
170+
171+ // <SNIP>
172+ }
173+ ```
174+
175+
176+
177+ ### Windows 10 Universal ###
178+
179+ ** MainPage.xaml**
180+
181+ ``` XML
182+ <forms : WindowsPage
183+ x : Class =" NUnit.Runner.Tests.MainPage"
184+ xmlns =" http://schemas.microsoft.com/winfx/2006/xaml/presentation"
185+ xmlns : x =" http://schemas.microsoft.com/winfx/2006/xaml"
186+ xmlns : local =" using:NUnit.Runner.Tests"
187+ xmlns : d =" http://schemas.microsoft.com/expression/blend/2008"
188+ xmlns : mc =" http://schemas.openxmlformats.org/markup-compatibility/2006"
189+ xmlns : forms =" using:Xamarin.Forms.Platform.WinRT"
190+ mc : Ignorable =" d" >
191+
192+ <Grid Background =" {ThemeResource ApplicationPageBackgroundThemeBrush}" >
193+
194+ </Grid >
195+ </forms : WindowsPage >
196+ ```
197+
198+ ** MainPage.xaml.cs**
199+
200+ ``` C#
201+ public sealed partial class MainPage : WindowsPage
202+ {
203+ public MainPage ()
204+ {
205+ InitializeComponent ();
206+
207+ // Windows Universal will not load all tests within the current project,
208+ // you must do it explicitly below
209+ var nunit = new NUnit .Runner .App ();
210+
211+ // If you want to add tests in another assembly, add a reference and
212+ // duplicate the following line with a type from the referenced assembly
213+ nunit .AddTestAssembly (typeof (MainPage ).GetTypeInfo ().Assembly );
214+
215+ // Do you want to automatically run tests when the app starts?
216+ nunit .AutoRun = true ;
217+
218+ LoadApplication (nunit );
219+ }
220+ }
221+ ```
222+
223+ ** App.xaml.cs**
224+
225+ ``` C#
226+ protected override void OnLaunched (LaunchActivatedEventArgs e )
227+ {
228+ // <SNIP>
229+
230+ Frame rootFrame = Window .Current .Content as Frame ;
231+
232+ // Do not repeat app initialization when the Window already has content,
233+ // just ensure that the window is active
234+ if (rootFrame == null )
235+ {
236+ // Create a Frame to act as the navigation context and navigate to the first page
237+ rootFrame = new Frame ();
238+
239+ rootFrame .NavigationFailed += OnNavigationFailed ;
240+
241+ // ==> ADD THIS LINE <==
242+ Xamarin .Forms .Forms .Init (e );
243+
244+ if (e .PreviousExecutionState == ApplicationExecutionState .Terminated )
245+ {
246+ // TODO: Load state from previously suspended application
247+ }
248+
249+ // Place the frame in the current Window
250+ Window .Current .Content = rootFrame ;
251+ }
252+
253+ // <SNIP>
166254 }
167255```
0 commit comments