Skip to content

Commit

Permalink
Add workaround for TRX Writer bug
Browse files Browse the repository at this point in the history
  • Loading branch information
dotMorten committed Nov 5, 2023
1 parent fb03a2a commit f7e0931
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/TestAppRunner/TestAppRunner/TestAppRunner.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<PackageTags>Unit Test, Xamarin, Android, iOS, Test, Testing, MSTest, VSTest, TestFX, TRX, MAUI</PackageTags>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<FileVersion>2.0.0.0</FileVersion>
<Version>2.0.0-rc.4</Version>
<Version>2.0.0-rc.5</Version>
<Description>A .NET MAUI-based UnitTest Runner to execute MSTests on Android, iOS and MacCatalyst. The app supports custom test logging, and has built-in support for outputting a TRX test report and being remote controlled from commandline.</Description>
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
Expand Down
9 changes: 8 additions & 1 deletion src/TestAppRunner/TestAppRunner/ViewModels/TestRunnerVM.cs
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,14 @@ private async Task<IEnumerable<TestResult>> Run_Internal(IEnumerable<TestCase> t
}
if (trxWriter != null)
{
trxWriter?.OnTestRunComplete(new Microsoft.VisualStudio.TestPlatform.ObjectModel.Client.TestRunCompleteEventArgs(null, false, true, null, null, TimeSpan.Zero));
try
{
trxWriter?.OnTestRunComplete(new Microsoft.VisualStudio.TestPlatform.ObjectModel.Client.TestRunCompleteEventArgs(null, false, false, null, null, TimeSpan.Zero));
}
catch(PlatformNotSupportedException) // Throws due to https://github.com/microsoft/vstest/issues/4736. However it's thrown after TRX is written
{
Debug.Assert(File.Exists(Settings.TrxOutputPath));
}
trxWriter = null;
Logger.Log($"TRXREPORT LOCATION: {Settings.TrxOutputPath}");
}
Expand Down
11 changes: 8 additions & 3 deletions src/TestAppRunner/TestAppRunner/Views/AllTestsPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,17 @@ private void RunFailed_Clicked()

private void Save_Report_Clicked()
{
#if MAUI
string path = Path.Combine(Path.GetTempPath(), DateTime.Now.ToString("yyyyMMdd_HHmmss") + ".trx");
TrxWriter.GenerateReport(path, TestRunnerVM.Instance.Tests.Select(t => t.Result).Where(r=>r is not null));
try
{
TrxWriter.GenerateReport(path, TestRunnerVM.Instance.Tests.Select(t => t.Result).Where(r => r is not null));
}
catch (PlatformNotSupportedException) // Throws due to https://github.com/microsoft/vstest/issues/4736. However it's thrown after TRX is written
{
System.Diagnostics.Debug.Assert(File.Exists(path));
}
Microsoft.Maui.ApplicationModel.DataTransfer.Share.RequestAsync(
new Microsoft.Maui.ApplicationModel.DataTransfer.ShareFileRequest("TRX Test Report", new Microsoft.Maui.ApplicationModel.DataTransfer.ShareFile(path)));
#endif
}
private void StopRun_Clicked()
{
Expand Down

0 comments on commit f7e0931

Please sign in to comment.