Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
33 changes: 33 additions & 0 deletions docs/UITesting-Guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,39 @@ For rapid development and debugging, you can run specific tests directly:

For comprehensive CI-like test runs:

Android, iOS, MacCatalyst, and Windows CI runs retry once after a failure using
the shared UI test runner. For an exact category group such as
`TestCategory=Editor|TestCategory=Effects|TestCategory=Essentials`, the retry runs
only categories containing failed tests or fixtures. NUnit XML provides inherited
fixture and method categories; only categories in the original group are selected.
Missing, incomplete, or unmappable results fall back to the original filter with
a warning. Custom filters retain their original selection, and local runs do not retry.

On iOS, MacCatalyst, and Windows CI, preparation and test-project build phases
also have one bounded retry per failed phase, before test execution starts.
These retries do not restart completed tests. Local runs and device-test targets
do not retry setup.

NUnit XML is checked whether VSTest succeeds or throws. Fixture-only failures
such as `OneTimeTearDown` errors trigger the same category-based retry and are
recorded as TRX run errors if they persist. Missing or malformed reports are
logged without replacing an existing VSTest exception.

The published TRX combines untouched first-attempt results with retry results.
Failures not reported by the retry remain failures. Fixture errors are cleared
only when retry NUnit XML confirms that the same fixture in the same assembly
completed successfully; omitted, skipped, or incomplete fixtures remain run
errors, even if all retained test cases passed.

Available raw TRX and NUnit XML files are copied before XML parsing,
reconciliation, or category selection, including for full-filter retries. The
first attempt's snapshots are under `nunit-<id>/raw/` and the retry's snapshots
under `nunit-<id>/retry/raw/`, beneath the result directory. Retry output always
uses a separate directory, even when the first TRX is missing or malformed.
Only the combined top-level TRX is published; if the first TRX cannot be read,
the retry TRX is published instead. If raw reports cannot be archived, the runner
stops without retrying or overwriting the available evidence.

**Android:**

```powershell
Expand Down
9 changes: 7 additions & 2 deletions eng/cake/dotnet.cake
Original file line number Diff line number Diff line change
Expand Up @@ -900,7 +900,7 @@ void RunMSBuildWithDotNet(
DotNetBuild(sln, dotnetBuildSettings);
}

void RunTestWithLocalDotNet(string csproj, string config, string pathDotnet = null, Dictionary<string, string> argsExtra = null, bool noBuild = false, string resultsFileNameWithoutExtension = null, string filter = "", int maxCpuCount = 0)
void RunTestWithLocalDotNet(string csproj, string config, string pathDotnet = null, Dictionary<string, string> argsExtra = null, bool noBuild = false, string resultsFileNameWithoutExtension = null, string filter = "", int maxCpuCount = 0, string resultsDirectory = null, string nunitResultsDirectory = null)
{
if (string.IsNullOrWhiteSpace(filter))
{
Expand Down Expand Up @@ -949,7 +949,7 @@ void RunTestWithLocalDotNet(string csproj, string config, string pathDotnet = nu
$"trx;LogFileName={results}",
$"console;verbosity=normal"
},
ResultsDirectory = GetTestResultsDirectory(),
ResultsDirectory = resultsDirectory == null ? GetTestResultsDirectory() : new DirectoryPath(resultsDirectory),
// Verbosity = Cake.Common.Tools.DotNetCore.DotNetCoreVerbosity.Diagnostic,

ArgumentCustomization = args =>
Expand Down Expand Up @@ -977,6 +977,11 @@ void RunTestWithLocalDotNet(string csproj, string config, string pathDotnet = nu
// https://github.com/microsoft/vstest/issues/5112
args.Append($"/p:VStestUseMSBuildOutput=false");

if (!string.IsNullOrEmpty(nunitResultsDirectory))
{
args.Append("--").AppendQuoted($"NUnit.TestOutputXml={nunitResultsDirectory}");
}

return args;
}
};
Expand Down
23 changes: 1 addition & 22 deletions eng/devices/android.cake
Original file line number Diff line number Diff line change
Expand Up @@ -286,29 +286,8 @@ void ExecuteUITests(string project, string app, string appPackageName, string de

SetEnvironmentVariable("APPIUM_LOG_FILE", appiumLog);

int numOfRetries = 0;

if (IsCIBuild())
numOfRetries = 1;

Information("Run UITests project {0}", project);
for(int retryCount = 0; retryCount <= numOfRetries; retryCount++)
{
try
{
Information("Retry UITests run Count: {0}", retryCount);
RunTestWithLocalDotNet(project, config, pathDotnet: toolPath, noBuild: true, resultsFileNameWithoutExtension: resultsFileName);
break;
}
catch(Exception)
{
if (retryCount == numOfRetries)
{
WriteLogCat();
throw;
}
}
}
RunUITestsWithRetry(project, config, toolPath, resultsFileName, () => WriteLogCat());
Information("UI Tests completed.");
}

Expand Down
61 changes: 32 additions & 29 deletions eng/devices/catalyst.cake
Original file line number Diff line number Diff line change
Expand Up @@ -111,47 +111,50 @@ void ExecuteUITests(string project, string app, string device, string resultsDir
{
// Setup environment for UI tests
Information("Starting UI Tests...");
var testApp = GetTestApplications(app, device, config, tfm, rid).FirstOrDefault();

Information($"Testing Device: {device}");
Information($"Testing App Project: {app}");
Information($"Testing App: {testApp}");
Information($"Results Directory: {resultsDir}");
var name = System.IO.Path.GetFileNameWithoutExtension(project);
var binlog = $"{binDir}/{name}-{config}-mac.binlog";
var resultsFileName = SanitizeTestResultsFilename($"{name}-{config}-catalyst-{testFilter}");
var appiumLog = $"{binDir}/appium_mac_{resultsFileName}.log";

if (string.IsNullOrEmpty(testApp))
RunUITestSetupWithRetry(() =>
{
throw new Exception("UI Test application path not specified.");
}
var testApp = GetTestApplications(app, device, config, tfm, rid).FirstOrDefault();

// Launch the app so it can be found by the test runner
StartProcess("chmod", $"+x {testApp}/Contents/MacOS/Controls.TestCases.HostApp");
Information($"Testing Device: {device}");
Information($"Testing App Project: {app}");
Information($"Testing App: {testApp}");
Information($"Results Directory: {resultsDir}");

var p = new System.Diagnostics.Process();
p.StartInfo.UseShellExecute = true;
p.StartInfo.FileName = "open";
p.StartInfo.Arguments = testApp;
p.Start();
if (string.IsNullOrEmpty(testApp))
{
throw new Exception("UI Test application path not specified.");
}

Information("Build UITests project {0}", project);
// Launch the app so it can be found by the test runner
StartProcess("chmod", $"+x {testApp}/Contents/MacOS/Controls.TestCases.HostApp");

var name = System.IO.Path.GetFileNameWithoutExtension(project);
var binlog = $"{binDir}/{name}-{config}-mac.binlog";
var resultsFileName = SanitizeTestResultsFilename($"{name}-{config}-catalyst-{testFilter}");
var appiumLog = $"{binDir}/appium_mac_{resultsFileName}.log";
var p = new System.Diagnostics.Process();
p.StartInfo.UseShellExecute = true;
p.StartInfo.FileName = "open";
p.StartInfo.Arguments = testApp;
p.Start();

DotNetBuild(project, new DotNetBuildSettings
{
Configuration = config,
ToolPath = toolPath,
ArgumentCustomization = args => args
.Append("/p:ExtraDefineConstants=MACUITEST")
.Append("/bl:" + binlog)
Information("Build UITests project {0}", project);

DotNetBuild(project, new DotNetBuildSettings
{
Configuration = config,
ToolPath = toolPath,
ArgumentCustomization = args => args
.Append("/p:ExtraDefineConstants=MACUITEST")
.Append("/bl:" + binlog)
});
});

SetEnvironmentVariable("APPIUM_LOG_FILE", appiumLog);

Information("Run UITests project {0}", project);
RunTestWithLocalDotNet(project, config, pathDotnet: toolPath, noBuild: true, resultsFileNameWithoutExtension: resultsFileName);
RunUITestsWithRetry(project, config, toolPath, resultsFileName);
Information("UI Tests completed.");
}

Expand Down
14 changes: 7 additions & 7 deletions eng/devices/ios.cake
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ Teardown(context =>
});

Task("connectToDevice")
.Does(() =>
.Does(() => RunUITestSetupWithRetry(() =>
{
if (!deviceBoot)
{
Expand All @@ -73,7 +73,7 @@ Task("connectToDevice")
GetSimulators(testDevice, dotnetToolPath);
ResetSimulators(testDevice, dotnetToolPath);
}
});
}));

Task("Cleanup")
.Does(() =>
Expand Down Expand Up @@ -116,10 +116,10 @@ Task("uitest-build")

Task("uitest-prepare")
.IsDependentOn("connectToDevice")
.Does(() =>
.Does(() => RunUITestSetupWithRetry(() =>
{
ExecutePrepareUITests(projectPath, testAppProjectPath, testDevice, testResultsPath, binlogDirectory, configuration, targetFramework, runtimeIdentifier, iosVersion, dotnetToolPath, headless);
});
}));

Task("uitest")
.IsDependentOn("uitest-prepare")
Expand Down Expand Up @@ -240,15 +240,15 @@ void ExecuteUITests(string project, string app, string device, string resultsDir
var resultsFileName = SanitizeTestResultsFilename($"{name}-{config}-ios-{testFilter}");
var appiumLog = $"{binDir}/appium_ios_{resultsFileName}.log";

DotNetBuild(project, new DotNetBuildSettings
RunUITestSetupWithRetry(() => DotNetBuild(project, new DotNetBuildSettings
{
Configuration = config,
ToolPath = toolPath,
ArgumentCustomization = args => args
.Append("/p:ExtraDefineConstants=IOSUITEST")
.Append($"/p:_UseNativeAot={USE_NATIVE_AOT}")
.Append("/bl:" + binlog)
});
}));

var TEST_CONFIGURATION_ARGS = Argument("TEST_CONFIGURATION_ARGS", EnvironmentVariable("TEST_CONFIGURATION_ARGS") ?? "");

Expand All @@ -257,7 +257,7 @@ void ExecuteUITests(string project, string app, string device, string resultsDir
SetEnvironmentVariable("APPIUM_LOG_FILE", appiumLog);

Information("Run UITests project {0}", project);
RunTestWithLocalDotNet(project, config, pathDotnet: toolPath, noBuild: true, resultsFileNameWithoutExtension: resultsFileName);
RunUITestsWithRetry(project, config, toolPath, resultsFileName);
Information("UI Tests completed.");
}

Expand Down
Loading
Loading