diff --git a/src/runner/nunit.runner.Droid/nunit.runner.Droid.csproj b/src/runner/nunit.runner.Droid/nunit.runner.Droid.csproj
index b0a3334..9e10cf3 100644
--- a/src/runner/nunit.runner.Droid/nunit.runner.Droid.csproj
+++ b/src/runner/nunit.runner.Droid/nunit.runner.Droid.csproj
@@ -13,7 +13,7 @@
Resources\Resource.Designer.cs
Off
True
- v6.0
+ v7.0
True
diff --git a/src/runner/nunit.runner/Services/TestOptions.cs b/src/runner/nunit.runner/Services/TestOptions.cs
index 227f12d..1fa23cc 100644
--- a/src/runner/nunit.runner/Services/TestOptions.cs
+++ b/src/runner/nunit.runner/Services/TestOptions.cs
@@ -21,6 +21,8 @@
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// ***********************************************************************
+using PCLStorage;
+
namespace NUnit.Runner.Services
{
///
@@ -28,6 +30,19 @@ namespace NUnit.Runner.Services
///
public class TestOptions
{
+ const string OutputFolderName = "NUnitTestOutput";
+ const string OutputXmlReportName = "TestResults.xml";
+
+ private string _resultFilePath;
+
+ ///
+ /// Constructor
+ ///
+ public TestOptions()
+ {
+ _resultFilePath = System.IO.Path.Combine(FileSystem.Current.LocalStorage.Path, OutputFolderName, OutputXmlReportName);
+ }
+
///
/// If True, the tests will run automatically when the app starts
/// otherwise you must run them manually.
@@ -44,5 +59,15 @@ public class TestOptions
/// Creates a NUnit Xml result file on the host file system using PCLStorage library.
///
public bool CreateXmlResultFile { get; set; }
+
+ ///
+ /// File path for the xml result file
+ /// Default is [LocalStorage]/NUnitTestOutput/TestResults.xml
+ ///
+ public string ResultFilePath
+ {
+ get { return _resultFilePath; }
+ set { _resultFilePath = value; }
+ }
}
}
diff --git a/src/runner/nunit.runner/Services/XmlFileProcessor.cs b/src/runner/nunit.runner/Services/XmlFileProcessor.cs
index e884d82..6b9bf84 100644
--- a/src/runner/nunit.runner/Services/XmlFileProcessor.cs
+++ b/src/runner/nunit.runner/Services/XmlFileProcessor.cs
@@ -64,24 +64,43 @@ 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 = new FileSystemFolder(outputFolderName);
+ 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);
}
}
+
+ ///
+ /// Create a folder from the full folder path if it does not exist
+ /// Throws exception if acess to the path is denied
+ ///
+ ///
+ ///
+ 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++)
+ {
+ IFolder folder = new FileSystemFolder(path);
+
+ var res = await folder.CheckExistsAsync(segments[i + 1]);
+ if (res != ExistenceCheckResult.FolderExists)
+ {
+ await folder.CreateFolderAsync(segments[i + 1], CreationCollisionOption.OpenIfExists);
+ }
+ path = Path.Combine(path, segments[i + 1]);
+ }
+ }
}
}
\ No newline at end of file
diff --git a/src/tests/nunit.runner.tests.Droid/MainActivity.cs b/src/tests/nunit.runner.tests.Droid/MainActivity.cs
index 95e80d2..be0166f 100644
--- a/src/tests/nunit.runner.tests.Droid/MainActivity.cs
+++ b/src/tests/nunit.runner.tests.Droid/MainActivity.cs
@@ -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;
@@ -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", "Results.xml")
};
LoadApplication(nunit);
diff --git a/src/tests/nunit.runner.tests.Droid/Properties/AndroidManifest.xml b/src/tests/nunit.runner.tests.Droid/Properties/AndroidManifest.xml
index 2818a19..1671a24 100644
--- a/src/tests/nunit.runner.tests.Droid/Properties/AndroidManifest.xml
+++ b/src/tests/nunit.runner.tests.Droid/Properties/AndroidManifest.xml
@@ -1,5 +1,7 @@
-
+
+
+
\ No newline at end of file
diff --git a/src/tests/nunit.runner.tests.Droid/nunit.runner.tests.Droid.csproj b/src/tests/nunit.runner.tests.Droid/nunit.runner.tests.Droid.csproj
index cbfd946..ba96b97 100644
--- a/src/tests/nunit.runner.tests.Droid/nunit.runner.tests.Droid.csproj
+++ b/src/tests/nunit.runner.tests.Droid/nunit.runner.tests.Droid.csproj
@@ -24,7 +24,7 @@
True
- v6.0
+ v7.0
true