Skip to content
This repository was archived by the owner on Jan 8, 2023. It is now read-only.

Commit f294c7d

Browse files
committed
Added Universal Windows support back in - Fixes #28
1 parent 826c7ac commit f294c7d

File tree

2 files changed

+95
-3
lines changed

2 files changed

+95
-3
lines changed

README.md

Lines changed: 90 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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

99
In your solution;
1010

1111
1. 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
1516
2. Add the `nunit.xamarin` NuGet package to your projects
1617
3. 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.
2022
4. 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()`.
2224
6. Write your unit tests in this project, or in a shared project
2325
7. Build and run the tests on your device or emulator
2426

@@ -137,6 +139,8 @@ public sealed partial class MainPage : WindowsPhonePage
137139
```C#
138140
protected 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
```

nuget/nunit.runners.xamarin.nuspec

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
Supported Xamarin platforms:
1212
- Android
1313
- iOS
14-
- Windows Phone 8.1</description>
14+
- Windows Phone 8.1
15+
- Windows 10 Universal Apps</description>
1516
<summary>NUnit 3.0 runner components for Xamarin</summary>
1617
<tags>nunit xamarin android ios monoandroid monotouch winphone tdd unit test testing</tags>
1718
<language>en-US</language>
@@ -41,5 +42,8 @@ Supported Xamarin platforms:
4142
<file src="nuget\wpa81\MainPage.xaml.cs.txt.pp" target="content\wpa81\MainPage.xaml.cs.txt.pp" />
4243
<file src="src\runner\nunit.runner.wp81\bin\Release\nunit.runner.wp81.dll" target="lib\wpa81\nunit.runner.wp81.dll" />
4344
<file src="src\runner\nunit.runner.wp81\bin\Release\nunit.runner.wp81.xml" target="lib\wpa81\nunit.runner.wp81.xml" />
45+
46+
<file src="src\runner\nunit.runner.uwp\bin\Release\nunit.runner.uwp.dll" target="lib\uap10.0\nunit.runner.uwp.dll" />
47+
<file src="src\runner\nunit.runner.uwp\bin\Release\nunit.runner.uwp.xml" target="lib\uap10.0\nunit.runner.uwp.xml" />
4448
</files>
4549
</package>

0 commit comments

Comments
 (0)