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

Commit 449bd88

Browse files
committed
Merge pull request #33 from nunit/release-3.0.0
Release 3.0.0
2 parents 3123d9b + f294c7d commit 449bd88

File tree

8 files changed

+266
-50
lines changed

8 files changed

+266
-50
lines changed

README.md

Lines changed: 224 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -4,64 +4,252 @@ NUnit test runners for Xamarin and mobile devices
44

55
## How to Use ##
66

7-
The NuGet packages are nearly ready and we will likely create project templates, but until that is done,
8-
you will need to build from source. For this, you will need a Xamarin trial or subscription.
7+
**Project templates will be coming soon**, in the meantime...
8+
9+
In your solution;
10+
11+
1. Add a new project to your solution
12+
- `Blank App (Android)` for Android,
13+
- `Blank App (iOS)` for iOS,
14+
- `Blank App (Windows Phone)` for Windows Phone 8.1
15+
- `Blank App (Universal Windows)` for Windows 10 Universal
16+
2. Add the `nunit.xamarin` NuGet package to your projects
17+
3. Text files will be added to your project, open them and copy over the coresponding file in each project as appropriate.
18+
- `MainActivity.cs.txt` for Android,
19+
- `AppDelegate.cs.txt` for iOS, or
20+
- `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.
22+
4. Once you are done with them, you can delete the text files that were added to your project.
23+
5. On Windows Phone and Windows Universal, you will also need to add `Xamarin.Forms.Forms.Init(e);` to `App.OnLaunched()`.
24+
6. Write your unit tests in this project, or in a shared project
25+
7. Build and run the tests on your device or emulator
926

10-
1. Clone this repository
11-
2. Open `nunit.runner.sln` in Visual Studio with Xamarin installed, or in Xamarin Studio.
12-
3. Create a release build of the solution.
27+
### Android ###
1328

14-
Then in your solution;
29+
**MainActivity.cs**
1530

16-
1. Add a new `Blank App (Android)` or `Blank App (iOS)` to your solution
17-
2. Add NuGet packages to your project for `NUnit 3.0.0-beta-4` and `Xamarin.Forms 1.4.4.6392`
18-
3. Browse and add a reference to the `nunit.runner.droid.dll` or `nunit.runner.ios.dll` that you built
19-
4. Write your unit tests in this project, or in a shared project
20-
5. Change the base class of `MainActivity` on Android to `global::Xamarin.Forms.Platform.Android.FormsApplicationActivity`
21-
6. Change the base class of `AppDelegate` on iOS to `global::Xamarin.Forms.Platform.iOS.FormsApplicationDelegate`
22-
7. Change MainActivity.OnCreate() on Android or AppDelegate.FinishedLaunching() on iOS
23-
8. Build and run the tests on your device or emulator
31+
```C#
32+
[Activity(Label = "NUnit 3.0", MainLauncher = true, Theme = "@android:style/Theme.Holo.Light", ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
33+
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsApplicationActivity
34+
{
35+
protected override void OnCreate(Bundle savedInstanceState)
36+
{
37+
base.OnCreate(savedInstanceState);
2438

25-
### Android ###
39+
global::Xamarin.Forms.Forms.Init(this, savedInstanceState);
40+
41+
// This will load all tests within the current project
42+
var nunit = new NUnit.Runner.App();
43+
44+
// If you want to add tests in another assembly
45+
//nunit.AddTestAssembly(typeof(MyTests).Assembly);
46+
47+
// Do you want to automatically run tests when the app starts?
48+
nunit.AutoRun = true;
49+
50+
LoadApplication(nunit);
51+
}
52+
}
53+
```
54+
### iOS ###
55+
56+
**AppDelegate.cs**
2657

2758
```C#
28-
protected override void OnCreate(Bundle savedInstanceState)
59+
[Register("AppDelegate")]
60+
public partial class AppDelegate : global::Xamarin.Forms.Platform.iOS.FormsApplicationDelegate
2961
{
30-
base.OnCreate(savedInstanceState);
62+
//
63+
// This method is invoked when the application has loaded and is ready to run. In this
64+
// method you should instantiate the window, load the UI into it and then make the window
65+
// visible.
66+
//
67+
// You have 17 seconds to return from this method, or iOS will terminate your application.
68+
//
69+
public override bool FinishedLaunching(UIApplication app, NSDictionary options)
70+
{
71+
global::Xamarin.Forms.Forms.Init();
72+
73+
// This will load all tests within the current project
74+
var nunit = new NUnit.Runner.App();
75+
76+
// If you want to add tests in another assembly
77+
//nunit.AddTestAssembly(typeof(MyTests).Assembly);
78+
79+
// Do you want to automatically run tests when the app starts?
80+
nunit.AutoRun = true;
81+
82+
LoadApplication(nunit);
83+
84+
return base.FinishedLaunching(app, options);
85+
}
86+
}
87+
```
3188

32-
global::Xamarin.Forms.Forms.Init(this, savedInstanceState);
89+
### Windows Phone 8.1 ###
3390

34-
// This will load all tests within the current project
35-
var nunit = new NUnit.Runner.App();
91+
**MainPage.xaml**
3692

37-
// If you want to add tests in another assembly
38-
//nunit.AddTestAssembly(typof(MyTests).Assembly);
93+
```XML
94+
<forms:WindowsPhonePage
95+
x:Class="Xamarin.Test.wp81.MainPage"
96+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
97+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
98+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
99+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
100+
xmlns:forms="using:Xamarin.Forms.Platform.WinRT"
101+
mc:Ignorable="d"
102+
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
39103

40-
// Do you want to automatically run tests when the app starts?
41-
nunit.AutoRun = true;
104+
<Grid>
42105

43-
LoadApplication(nunit);
106+
</Grid>
107+
</forms:WindowsPhonePage>
108+
```
109+
110+
**MainPage.xaml.cs**
111+
112+
```C#
113+
public sealed partial class MainPage : WindowsPhonePage
114+
{
115+
public MainPage()
116+
{
117+
InitializeComponent();
118+
119+
// Windows Phone will not load all tests within the current project,
120+
// you must do it explicitly below
121+
var nunit = new NUnit.Runner.App();
122+
123+
// If you want to add tests in another assembly, add a reference and
124+
// duplicate the following line with a type from the referenced assembly
125+
nunit.AddTestAssembly(typeof(MainPage).GetTypeInfo().Assembly);
126+
127+
// Do you want to automatically run tests when the app starts?
128+
nunit.AutoRun = true;
129+
130+
LoadApplication(nunit);
131+
132+
this.NavigationCacheMode = NavigationCacheMode.Required;
133+
}
44134
}
45135
```
46-
### iOS ###
136+
137+
**App.xaml.cs**
47138

48139
```C#
49-
public override bool FinishedLaunching(UIApplication app, NSDictionary options)
140+
protected override void OnLaunched(LaunchActivatedEventArgs e)
50141
{
51-
global::Xamarin.Forms.Forms.Init();
142+
// <SNIP>
143+
144+
Frame rootFrame = Window.Current.Content as Frame;
145+
146+
// Do not repeat app initialization when the Window already has content,
147+
// just ensure that the window is active
148+
if (rootFrame == null)
149+
{
150+
// Create a Frame to act as the navigation context and navigate to the first page
151+
rootFrame = new Frame();
152+
153+
// TODO: change this value to a cache size that is appropriate for your application
154+
rootFrame.CacheSize = 1;
52155

53-
// This will load all tests within the current project
54-
var nunit = new NUnit.Runner.App();
156+
// Set the default language
157+
rootFrame.Language = Windows.Globalization.ApplicationLanguages.Languages[0];
55158

56-
// If you want to add tests in another assembly
57-
//nunit.AddTestAssembly(typof(MyTests).Assembly);
159+
// ==> ADD THIS LINE <==
160+
Xamarin.Forms.Forms.Init(e);
58161

59-
// Do you want to automatically run tests when the app starts?
60-
nunit.AutoRun = true;
162+
if (e.PreviousExecutionState == ApplicationExecutionState.Terminated)
163+
{
164+
// TODO: Load state from previously suspended application
165+
}
61166

62-
LoadApplication(nunit);
167+
// Place the frame in the current Window
168+
Window.Current.Content = rootFrame;
169+
}
63170

64-
return base.FinishedLaunching(app, options);
171+
// <SNIP>
65172
}
66173
```
67174

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>
254+
}
255+
```

build.cake

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ Task("Clean")
5252
});
5353

5454
Task("Restore-NuGet-Packages")
55-
.IsDependentOn("Clean")
5655
.Does(() =>
5756
{
5857
NuGetRestore("./nunit.runner.sln", new NuGetRestoreSettings {

nuget/nunit.runners.xamarin.nuspec

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<package xmlns="http://schemas.microsoft.com/packaging/2011/10/nuspec.xsd">
33
<metadata minClientVersion="2.8.5">
4-
<id>nunit.runner.xamarin</id>
4+
<id>nunit.xamarin</id>
55
<version>$version$</version>
66
<title>NUnit 3.0 Xamarin Runner</title>
77
<authors>Rob Prouse</authors>
@@ -12,9 +12,9 @@ Supported Xamarin platforms:
1212
- Android
1313
- iOS
1414
- Windows Phone 8.1
15-
- Windows 10 Universal</description>
15+
- Windows 10 Universal Apps</description>
1616
<summary>NUnit 3.0 runner components for Xamarin</summary>
17-
<tags>nunit xamarin android ios monoandroid monotouch winphone uwp tdd unit test testing</tags>
17+
<tags>nunit xamarin android ios monoandroid monotouch winphone tdd unit test testing</tags>
1818
<language>en-US</language>
1919
<licenseUrl>http://nunit.org/nuget/nunit3-license.txt</licenseUrl>
2020
<projectUrl>https://github.com/nunit/nunit.xamarin</projectUrl>
@@ -25,24 +25,24 @@ Supported Xamarin platforms:
2525
<dependencies>
2626
<group>
2727
<dependency id="nunit" version="[3.0.0]" />
28-
<dependency id="Xamarin.Forms" version="1.5.1.6471" />
28+
<dependency id="Xamarin.Forms" version="1.5.0.6447" />
2929
</group>
3030
</dependencies>
3131
</metadata>
3232
<files>
33-
<file src="nuget\MonoAndroid10\MainActivity.cs.txt.pp" target="content\MonoAndroid10\MainActivity.cs.txt.pp" />
34-
<file src="src\runner\nunit.runner.Droid\bin\Release\nunit.runner.Droid.dll" target="lib\MonoAndroid10\nunit.runner.Droid.dll" />
35-
<file src="src\runner\nunit.runner.Droid\bin\Release\nunit.runner.Droid.xml" target="lib\MonoAndroid10\nunit.runner.Droid.xml" />
33+
<file src="nuget\MonoAndroid10\MainActivity.cs.txt.pp" target="content\MonoAndroid\MainActivity.cs.txt.pp" />
34+
<file src="src\runner\nunit.runner.Droid\bin\Release\nunit.runner.Droid.dll" target="lib\MonoAndroid\nunit.runner.Droid.dll" />
35+
<file src="src\runner\nunit.runner.Droid\bin\Release\nunit.runner.Droid.xml" target="lib\MonoAndroid\nunit.runner.Droid.xml" />
3636

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

41+
<file src="nuget\wpa81\MainPage.xaml.txt.pp" target="content\wpa81\MainPage.xaml.txt.pp" />
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" />
4445

45-
<file src="nuget\uap10.0\MainPage.xaml.cs.txt.pp" target="content\uap10.0\MainPage.xaml.cs.txt.pp" />
4646
<file src="src\runner\nunit.runner.uwp\bin\Release\nunit.runner.uwp.dll" target="lib\uap10.0\nunit.runner.uwp.dll" />
4747
<file src="src\runner\nunit.runner.uwp\bin\Release\nunit.runner.uwp.xml" target="lib\uap10.0\nunit.runner.uwp.xml" />
4848
</files>

nuget/uap10.0/MainPage.xaml.txt.pp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<forms:WindowsPage
2+
x:Class="$rootnamespace$.MainPage"
3+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
4+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
5+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
6+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
7+
xmlns:forms="using:Xamarin.Forms.Platform.WinRT"
8+
mc:Ignorable="d">
9+
10+
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
11+
12+
</Grid>
13+
</forms:WindowsPage>

nuget/wpa81/MainPage.xaml.txt.pp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<forms:WindowsPhonePage
2+
x:Class="$rootnamespace$.MainPage"
3+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
4+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
5+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
6+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
7+
xmlns:forms="using:Xamarin.Forms.Platform.WinRT"
8+
mc:Ignorable="d"
9+
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
10+
11+
<Grid>
12+
13+
</Grid>
14+
</forms:WindowsPhonePage>

nunit.runner.sln

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,14 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "MonoAndroid10", "MonoAndroi
4747
EndProject
4848
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "uap10.0", "uap10.0", "{6B2E96B2-DED0-4541-97CE-416C0C6A38DD}"
4949
ProjectSection(SolutionItems) = preProject
50-
MainPage.xaml.cs.txt.pp = MainPage.xaml.cs.txt.pp
50+
nuget\uap10.0\MainPage.xaml.cs.txt.pp = nuget\uap10.0\MainPage.xaml.cs.txt.pp
51+
nuget\uap10.0\MainPage.xaml.txt.pp = nuget\uap10.0\MainPage.xaml.txt.pp
5152
EndProjectSection
5253
EndProject
5354
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "wpa81", "wpa81", "{20C1F6F6-6CA3-4C75-9058-90A8CDABCEE9}"
5455
ProjectSection(SolutionItems) = preProject
5556
nuget\wpa81\MainPage.xaml.cs.txt.pp = nuget\wpa81\MainPage.xaml.cs.txt.pp
57+
nuget\wpa81\MainPage.xaml.txt.pp = nuget\wpa81\MainPage.xaml.txt.pp
5658
EndProjectSection
5759
EndProject
5860
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Xamarin.iOS10", "Xamarin.iOS10", "{30BB9B64-B2B7-4F09-BF00-D4C76849A540}"

0 commit comments

Comments
 (0)