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

Commit

Permalink
Merge pull request #33 from nunit/release-3.0.0
Browse files Browse the repository at this point in the history
Release 3.0.0
  • Loading branch information
rprouse committed Nov 18, 2015
2 parents 3123d9b + f294c7d commit 449bd88
Show file tree
Hide file tree
Showing 8 changed files with 266 additions and 50 deletions.
260 changes: 224 additions & 36 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
<forms:WindowsPhonePage
x:Class="Xamarin.Test.wp81.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
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"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">

// Do you want to automatically run tests when the app starts?
nunit.AutoRun = true;
<Grid>

LoadApplication(nunit);
</Grid>
</forms:WindowsPhonePage>
```

**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();
// <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();

// 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);
// <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>
}
```
1 change: 0 additions & 1 deletion build.cake
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ Task("Clean")
});

Task("Restore-NuGet-Packages")
.IsDependentOn("Clean")
.Does(() =>
{
NuGetRestore("./nunit.runner.sln", new NuGetRestoreSettings {
Expand Down
22 changes: 11 additions & 11 deletions nuget/nunit.runners.xamarin.nuspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2011/10/nuspec.xsd">
<metadata minClientVersion="2.8.5">
<id>nunit.runner.xamarin</id>
<id>nunit.xamarin</id>
<version>$version$</version>
<title>NUnit 3.0 Xamarin Runner</title>
<authors>Rob Prouse</authors>
Expand All @@ -12,9 +12,9 @@ Supported Xamarin platforms:
- Android
- iOS
- Windows Phone 8.1
- Windows 10 Universal</description>
- Windows 10 Universal Apps</description>
<summary>NUnit 3.0 runner components for Xamarin</summary>
<tags>nunit xamarin android ios monoandroid monotouch winphone uwp tdd unit test testing</tags>
<tags>nunit xamarin android ios monoandroid monotouch winphone tdd unit test testing</tags>
<language>en-US</language>
<licenseUrl>http://nunit.org/nuget/nunit3-license.txt</licenseUrl>
<projectUrl>https://github.com/nunit/nunit.xamarin</projectUrl>
Expand All @@ -25,24 +25,24 @@ Supported Xamarin platforms:
<dependencies>
<group>
<dependency id="nunit" version="[3.0.0]" />
<dependency id="Xamarin.Forms" version="1.5.1.6471" />
<dependency id="Xamarin.Forms" version="1.5.0.6447" />
</group>
</dependencies>
</metadata>
<files>
<file src="nuget\MonoAndroid10\MainActivity.cs.txt.pp" target="content\MonoAndroid10\MainActivity.cs.txt.pp" />
<file src="src\runner\nunit.runner.Droid\bin\Release\nunit.runner.Droid.dll" target="lib\MonoAndroid10\nunit.runner.Droid.dll" />
<file src="src\runner\nunit.runner.Droid\bin\Release\nunit.runner.Droid.xml" target="lib\MonoAndroid10\nunit.runner.Droid.xml" />
<file src="nuget\MonoAndroid10\MainActivity.cs.txt.pp" target="content\MonoAndroid\MainActivity.cs.txt.pp" />
<file src="src\runner\nunit.runner.Droid\bin\Release\nunit.runner.Droid.dll" target="lib\MonoAndroid\nunit.runner.Droid.dll" />
<file src="src\runner\nunit.runner.Droid\bin\Release\nunit.runner.Droid.xml" target="lib\MonoAndroid\nunit.runner.Droid.xml" />

<file src="nuget\Xamarin.iOS10\AppDelegate.cs.txt.pp" target="content\Xamarin.iOS10\AppDelegate.cs.txt.pp" />
<file src="src\runner\nunit.runner.iOS\bin\Release\nunit.runner.iOS.dll" target="lib\Xamarin.iOS10\nunit.runner.iOS.dll" />
<file src="src\runner\nunit.runner.iOS\bin\Release\nunit.runner.iOS.xml" target="lib\Xamarin.iOS10\nunit.runner.iOS.xml" />
<file src="nuget\Xamarin.iOS10\AppDelegate.cs.txt.pp" target="content\Xamarin.iOS\AppDelegate.cs.txt.pp" />
<file src="src\runner\nunit.runner.iOS\bin\Release\nunit.runner.iOS.dll" target="lib\Xamarin.iOS\nunit.runner.iOS.dll" />
<file src="src\runner\nunit.runner.iOS\bin\Release\nunit.runner.iOS.xml" target="lib\Xamarin.iOS\nunit.runner.iOS.xml" />

<file src="nuget\wpa81\MainPage.xaml.txt.pp" target="content\wpa81\MainPage.xaml.txt.pp" />
<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="nuget\uap10.0\MainPage.xaml.cs.txt.pp" target="content\uap10.0\MainPage.xaml.cs.txt.pp" />
<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>
Expand Down
File renamed without changes.
13 changes: 13 additions & 0 deletions nuget/uap10.0/MainPage.xaml.txt.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<forms:WindowsPage
x:Class="$rootnamespace$.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
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>
14 changes: 14 additions & 0 deletions nuget/wpa81/MainPage.xaml.txt.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<forms:WindowsPhonePage
x:Class="$rootnamespace$.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
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"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">

<Grid>

</Grid>
</forms:WindowsPhonePage>
4 changes: 3 additions & 1 deletion nunit.runner.sln
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down
Loading

0 comments on commit 449bd88

Please sign in to comment.