-
Notifications
You must be signed in to change notification settings - Fork 47
Added TestOption to change xml result file location #60
Changes from 2 commits
a3554fb
8f894a4
55b5989
ce7276a
0f44421
ddafa52
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) | ||
{ | ||
|
@@ -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__ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
IFolder folder = await FileSystem.Current.GetFolderFromPathAsync(path, CancellationToken.None); | ||
#else | ||
IFolder folder = await FileSystem.Current.GetFolderFromPathAsync(path.Replace('/', '\\'), CancellationToken.None); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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]); | ||
} | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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_123", "Results.xml") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you change |
||
}; | ||
|
||
LoadApplication(nunit); | ||
|
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" /> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
---|---|---|
@@ -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> | ||
|
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 |
---|---|---|
|
@@ -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> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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> | ||
|
@@ -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> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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> | ||
|
@@ -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" /> | ||
|
There was a problem hiding this comment.
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. ☺