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

Commit

Permalink
Added Universal Windows support back in - Fixes #28
Browse files Browse the repository at this point in the history
  • Loading branch information
rprouse committed Nov 18, 2015
1 parent 826c7ac commit f294c7d
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 3 deletions.
92 changes: 90 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,23 @@ 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;

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, 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

Expand Down Expand Up @@ -137,6 +139,8 @@ public sealed partial class MainPage : WindowsPhonePage
```C#
protected override void OnLaunched(LaunchActivatedEventArgs e)
{
// <SNIP>
Frame rootFrame = Window.Current.Content as Frame;

// Do not repeat app initialization when the Window already has content,
Expand All @@ -163,5 +167,89 @@ protected override void OnLaunched(LaunchActivatedEventArgs e)
// Place the frame in the current Window
Window.Current.Content = rootFrame;
}

// <SNIP>
}
```



### Windows 10 Universal ###

**MainPage.xaml**

```XML
<forms:WindowsPage
x:Class="NUnit.Runner.Tests.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:NUnit.Runner.Tests"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:forms="using:Xamarin.Forms.Platform.WinRT"
mc:Ignorable="d">

<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">

</Grid>
</forms:WindowsPage>
```

**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)
{
// <SNIP>
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;
}

// <SNIP>
}
```
6 changes: 5 additions & 1 deletion nuget/nunit.runners.xamarin.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
Supported Xamarin platforms:
- Android
- iOS
- Windows Phone 8.1</description>
- Windows Phone 8.1
- Windows 10 Universal Apps</description>
<summary>NUnit 3.0 runner components for Xamarin</summary>
<tags>nunit xamarin android ios monoandroid monotouch winphone tdd unit test testing</tags>
<language>en-US</language>
Expand Down Expand Up @@ -41,5 +42,8 @@ Supported Xamarin platforms:
<file src="nuget\wpa81\MainPage.xaml.cs.txt.pp" target="content\wpa81\MainPage.xaml.cs.txt.pp" />
<file src="src\runner\nunit.runner.wp81\bin\Release\nunit.runner.wp81.dll" target="lib\wpa81\nunit.runner.wp81.dll" />
<file src="src\runner\nunit.runner.wp81\bin\Release\nunit.runner.wp81.xml" target="lib\wpa81\nunit.runner.wp81.xml" />

<file src="src\runner\nunit.runner.uwp\bin\Release\nunit.runner.uwp.dll" target="lib\uap10.0\nunit.runner.uwp.dll" />
<file src="src\runner\nunit.runner.uwp\bin\Release\nunit.runner.uwp.xml" target="lib\uap10.0\nunit.runner.uwp.xml" />
</files>
</package>

0 comments on commit f294c7d

Please sign in to comment.