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

Added TestOption to change xml result file location #60

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/runner/nunit.runner.Droid/nunit.runner.Droid.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<AndroidResgenFile>Resources\Resource.Designer.cs</AndroidResgenFile>
<GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>
<DevInstrumentationEnabled>True</DevInstrumentationEnabled>
<TargetFrameworkVersion>v6.0</TargetFrameworkVersion>
<TargetFrameworkVersion>v7.0</TargetFrameworkVersion>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
<EmbedAssembliesIntoApk>True</EmbedAssembliesIntoApk>
Expand Down
11,887 changes: 6,464 additions & 5,423 deletions src/runner/nunit.runner.uwp/project.lock.json

Large diffs are not rendered by default.

24 changes: 24 additions & 0 deletions src/runner/nunit.runner/Services/TestOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,27 @@
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// ***********************************************************************

using PCLStorage;

namespace NUnit.Runner.Services
{
/// <summary>
/// Options for the device test suite.
/// </summary>
public class TestOptions
{
const string OutputXmlReportName = "TestResults.xml";

private string _resultFilePath;

/// <summary>
/// Constructor
/// </summary>
public TestOptions()
{
_resultFilePath = System.IO.Path.Combine(FileSystem.Current.LocalStorage.Path, OutputXmlReportName);
}

/// <summary>
/// If True, the tests will run automatically when the app starts
/// otherwise you must run them manually.
Expand All @@ -44,5 +58,15 @@ public class TestOptions
/// Creates a NUnit Xml result file on the host file system using PCLStorage library.
/// </summary>
public bool CreateXmlResultFile { get; set; }

/// <summary>
/// File path for the xml result file
/// Default is [LocalStorage]/NUnitTestOutput/TestResults.xml
/// </summary>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I'm reading right, I think this comment is out-dated, default is now just in localstorage? Looks like the behaviour was changed since the comment was written. ☺

public string ResultFilePath
{
get { return _resultFilePath; }
set { _resultFilePath = value; }
}
}
}
65 changes: 49 additions & 16 deletions src/runner/nunit.runner/Services/XmlFileProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,20 @@
using System;
using System.Diagnostics;
using System.IO;
using System.Threading;
using System.Threading.Tasks;

using NUnit.Framework.Interfaces;

using PCLStorage;

using CreationCollisionOption = PCLStorage.CreationCollisionOption;
using FileAccess = PCLStorage.FileAccess;

namespace NUnit.Runner.Services
{
class XmlFileProcessor : TestResultProcessor
{
public XmlFileProcessor(TestOptions options)
: base(options)
{
}
: base(options) { }

public override async Task Process(ITestResult testResult)
{
Expand All @@ -64,24 +62,59 @@ public override async Task Process(ITestResult testResult)

async Task WriteXmlResultFile(ITestResult testResult)
{
const string OutputFolderName = "NUnitTestOutput";
const string OutputXmlReportName = "TestResults.xml";
var localStorageFolder = FileSystem.Current.LocalStorage;
string outputFolderName = Path.GetDirectoryName(Options.ResultFilePath);
string outputXmlReportName = Path.GetFileName(Options.ResultFilePath);

var existResult = await localStorageFolder.CheckExistsAsync(OutputFolderName);
if (existResult == ExistenceCheckResult.FileExists)
{
var existingFile = await localStorageFolder.GetFileAsync(OutputFolderName);
await existingFile.DeleteAsync();
}
await CreateFolderRecursive(outputFolderName);

var outputFolder = await localStorageFolder.CreateFolderAsync(OutputFolderName, CreationCollisionOption.OpenIfExists);
IFile xmlResultFile = await outputFolder.CreateFileAsync(OutputXmlReportName, CreationCollisionOption.ReplaceExisting);
IFolder outputFolder =
await FileSystem.Current.GetFolderFromPathAsync(outputFolderName, CancellationToken.None);

IFile xmlResultFile =
await outputFolder.CreateFileAsync(outputXmlReportName, CreationCollisionOption.ReplaceExisting);
using (var resultFileStream = new StreamWriter(await xmlResultFile.OpenAsync(FileAccess.ReadAndWrite)))
{
string xmlString = testResult.ToXml(true).OuterXml;
await resultFileStream.WriteAsync(xmlString);
}
}

/// <summary>
/// Create a folder from the full folder path if it does not exist
/// Throws exception if acess to the path is denied
/// </summary>
/// <param name="folderPath"></param>
/// <returns></returns>
private static async Task CreateFolderRecursive(string folderPath)
{
string[] segments = new Uri(folderPath).Segments;

string path = segments[0];

for (int i = 0; i < segments.Length - 1; i++)
{
try
{
#if __DROID__
IFolder folder = await FileSystem.Current.GetFolderFromPathAsync(path, CancellationToken.None);
#elif __IOS__
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the Android and IOS code is the same, please change the first #if to #if __DROID__ || __IOS__

IFolder folder = await FileSystem.Current.GetFolderFromPathAsync(path, CancellationToken.None);
#else
IFolder folder = await FileSystem.Current.GetFolderFromPathAsync(path.Replace('/', '\\'), CancellationToken.None);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just curious, did you do the path replacement because it wasn't working? I thought Windows accepted the Linux path separators, but I might be wrong.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It crashed on the windows phone so I had to replace the slashes. It also doesn't work with Uri, I always thought it doesn't matter on the platform.

#endif
var res = await folder.CheckExistsAsync(segments[i + 1]);
if (res != ExistenceCheckResult.FolderExists)
{
await folder.CreateFolderAsync(segments[i + 1], CreationCollisionOption.OpenIfExists);
}
}
catch (Exception)
{
// ignore
}

path = Path.Combine(path, segments[i + 1]);
}
}
}
}
6 changes: 5 additions & 1 deletion src/tests/nunit.runner.tests.Droid/MainActivity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// ***********************************************************************

using System.IO;
using Android.App;
using Android.Content.PM;
using Android.OS;
Expand Down Expand Up @@ -56,7 +57,10 @@ protected override void OnCreate(Bundle savedInstanceState)
//TcpWriterParameters = new TcpWriterInfo("192.168.0.108", 13000),

// Creates a NUnit Xml result file on the host file system using PCLStorage library.
CreateXmlResultFile = true
CreateXmlResultFile = true,

// Choose a diffrent path for the xml result file
ResultFilePath = Path.Combine(Environment.ExternalStorageDirectory.Path, Environment.DirectoryDownloads, "Nunit_123", "Results.xml")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you change Nunit_123 back?

};

LoadApplication(nunit);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:installLocation="auto" package="nunit.runner.tests" android:versionCode="3" android:versionName="3.0">
<uses-sdk android:minSdkVersion="15" />
<application android:label="NUnit" android:icon="@drawable/icon"></application>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Permissions need to be set for other platforms

<application android:label="NUnit"></application>
</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
<EmbedAssembliesIntoApk>True</EmbedAssembliesIntoApk>
<TargetFrameworkVersion>v6.0</TargetFrameworkVersion>
<TargetFrameworkVersion>v7.0</TargetFrameworkVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand Down
7 changes: 6 additions & 1 deletion src/tests/nunit.runner.tests.iOS/AppDelegate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// ***********************************************************************

using System;
using System.IO;
using Foundation;

using NUnit.Runner.Services;
Expand Down Expand Up @@ -64,7 +66,10 @@ public override bool FinishedLaunching(UIApplication app, NSDictionary options)
//TcpWriterParameters = new TcpWriterInfo("192.168.0.108", 13000),

// Creates a NUnit Xml result file on the host file system using PCLStorage library.
CreateXmlResultFile = false
CreateXmlResultFile = true,

// Choose a diffrent path for the xml result file (ios file share / library directory)
ResultFilePath = Path.Combine(NSFileManager.DefaultManager.GetUrls(NSSearchPathDirectory.LibraryDirectory, NSSearchPathDomain.User)[0].Path, "Results.xml")
};

LoadApplication(nunit);
Expand Down
6 changes: 2 additions & 4 deletions src/tests/nunit.runner.tests.iOS/Entitlements.plist
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
</dict>
<dict/>
</plist>

102 changes: 53 additions & 49 deletions src/tests/nunit.runner.tests.iOS/Info.plist
Original file line number Diff line number Diff line change
@@ -1,52 +1,56 @@
<?xml version="1.0" encoding="UTF-8"?>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>UIDeviceFamily</key>
<array>
<integer>1</integer>
<integer>2</integer>
</array>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>UISupportedInterfaceOrientations~ipad</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>MinimumOSVersion</key>
<string>6.0</string>
<key>CFBundleDisplayName</key>
<string>nunit.runner</string>
<key>CFBundleIdentifier</key>
<string>com.yourcompany.nunit.runner</string>
<key>CFBundleVersion</key>
<string>1.0</string>
<key>CFBundleIconFiles</key>
<array>
<string>Icon-60@2x</string>
<string>Icon-60@3x</string>
<string>Icon-76</string>
<string>Icon-76@2x</string>
<string>Default</string>
<string>Default@2x</string>
<string>Default-568h@2x</string>
<string>Default-Portrait</string>
<string>Default-Portrait@2x</string>
<string>Icon-Small-40</string>
<string>Icon-Small-40@2x</string>
<string>Icon-Small-40@3x</string>
<string>Icon-Small</string>
<string>Icon-Small@2x</string>
<string>Icon-Small@3x</string>
</array>
<key>UILaunchStoryboardName</key>
<string>LaunchScreen</string>
</dict>
<dict>
<key>UIDeviceFamily</key>
<array>
<integer>1</integer>
<integer>2</integer>
</array>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>UISupportedInterfaceOrientations~ipad</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>MinimumOSVersion</key>
<string>6.0</string>
<key>CFBundleDisplayName</key>
<string>nunit.runner</string>
<key>CFBundleIdentifier</key>
<string>com.yourcompany.nunit.runner</string>
<key>CFBundleVersion</key>
<string>1.0</string>
<key>CFBundleIconFiles</key>
<array>
<string>Icon-60@2x</string>
<string>Icon-60@3x</string>
<string>Icon-76</string>
<string>Icon-76@2x</string>
<string>Default</string>
<string>Default@2x</string>
<string>Default-568h@2x</string>
<string>Default-Portrait</string>
<string>Default-Portrait@2x</string>
<string>Icon-Small-40</string>
<string>Icon-Small-40@2x</string>
<string>Icon-Small-40@3x</string>
<string>Icon-Small</string>
<string>Icon-Small@2x</string>
<string>Icon-Small@3x</string>
</array>
<key>UILaunchStoryboardName</key>
<string>LaunchScreen</string>
<key>CFBundleShortVersionString</key>
<string></string>
<key>UIFileSharingEnabled</key>
<true/>
</dict>
</plist>
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
<MtouchLink>None</MtouchLink>
<MtouchDebug>true</MtouchDebug>
<CodesignEntitlements>Entitlements.plist</CodesignEntitlements>
<CodesignKey>iPhone Developer: Christian Schmid (R65G567HMV)</CodesignKey>
<CodesignProvision>dccfb495-a21d-4e42-8f9b-09f3126395e5</CodesignProvision>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs to be removed.

</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|iPhoneSimulator' ">
<DebugType>none</DebugType>
Expand All @@ -47,9 +49,10 @@
<WarningLevel>4</WarningLevel>
<ConsolePause>false</ConsolePause>
<MtouchArch>ARMv7, ARM64</MtouchArch>
<CodesignKey>iPhone Developer</CodesignKey>
<CodesignKey>iPhone Developer: Christian Schmid (R65G567HMV)</CodesignKey>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to be removed.

<MtouchDebug>true</MtouchDebug>
<CodesignEntitlements>Entitlements.plist</CodesignEntitlements>
<CodesignProvision>dccfb495-a21d-4e42-8f9b-09f3126395e5</CodesignProvision>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you should revert all changes in this file.

</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|iPhone' ">
<DebugType>none</DebugType>
Expand Down Expand Up @@ -91,7 +94,9 @@
<Compile Include="Main.cs" />
<Compile Include="AppDelegate.cs" />
<None Include="Entitlements.plist" />
<None Include="Info.plist" />
<None Include="Info.plist">
<SubType>Designer</SubType>
</None>
<Compile Include="Properties\AssemblyInfo.cs" />
<ITunesArtwork Include="iTunesArtwork" />
<None Include="packages.config" />
Expand Down
6 changes: 5 additions & 1 deletion src/tests/nunit.runner.tests.uwp/MainPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,11 @@ public MainPage()
//TcpWriterParameters = new TcpWriterInfo("192.168.0.108", 13000),

// Creates a NUnit Xml result file on the host file system using PCLStorage library.
CreateXmlResultFile = false
CreateXmlResultFile = false,

// Choose a diffrent path for the xml result file
// Windows phone 8.1 no permission to create subfolder in Windows.Storage.ApplicationData.Current.LocalFolder
// ResultFilePath = System.IO.Path.Combine(Windows.Storage.ApplicationData.Current.TemporaryFolder.Path, "Nunit", "Results.xml")
};

LoadApplication(nunit);
Expand Down
1 change: 1 addition & 0 deletions src/tests/nunit.runner.tests.uwp/Package.appxmanifest
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,6 @@
<Capabilities>
<Capability Name="internetClient" />
<Capability Name="privateNetworkClientServer" />
<uap:Capability Name="removableStorage" />
</Capabilities>
</Package>
Loading