diff --git a/src/Adapter/MSTestAdapter.PlatformServices/Deployment/TestRunDirectories.cs b/src/Adapter/MSTestAdapter.PlatformServices/Deployment/TestRunDirectories.cs index 22c6ba3714..96c37f0eae 100644 --- a/src/Adapter/MSTestAdapter.PlatformServices/Deployment/TestRunDirectories.cs +++ b/src/Adapter/MSTestAdapter.PlatformServices/Deployment/TestRunDirectories.cs @@ -45,9 +45,13 @@ public TestRunDirectories(string rootDirectory, string? firstTestSource, bool is RootDeploymentDirectory = rootDirectory; InDirectory = Path.Combine(RootDeploymentDirectory, DeploymentInDirectorySuffix); - OutDirectory = isAppDomainCreationDisabled && firstTestSource is not null - ? Path.GetDirectoryName(firstTestSource)! - : Path.Combine(RootDeploymentDirectory, DeploymentOutDirectorySuffix); + string? testSourceDirectory = isAppDomainCreationDisabled && !StringEx.IsNullOrEmpty(firstTestSource) + ? Path.GetDirectoryName(firstTestSource) + : null; + + OutDirectory = StringEx.IsNullOrEmpty(testSourceDirectory) + ? Path.Combine(RootDeploymentDirectory, DeploymentOutDirectorySuffix) + : testSourceDirectory; InMachineNameDirectory = Path.Combine(InDirectory, Environment.MachineName); } diff --git a/test/UnitTests/MSTestAdapter.PlatformServices.UnitTests/Deployment/TestRunDirectoriesTests.cs b/test/UnitTests/MSTestAdapter.PlatformServices.UnitTests/Deployment/TestRunDirectoriesTests.cs index 1fbf566525..e72d3c06f0 100644 --- a/test/UnitTests/MSTestAdapter.PlatformServices.UnitTests/Deployment/TestRunDirectoriesTests.cs +++ b/test/UnitTests/MSTestAdapter.PlatformServices.UnitTests/Deployment/TestRunDirectoriesTests.cs @@ -21,4 +21,19 @@ public void OutDirectoryShouldReturnCorrectDirectory() public void InMachineNameDirectoryShouldReturnMachineSpecificDeploymentDirectory() => _testRunDirectories.InMachineNameDirectory.Should().Be(Path.Combine(@"C:\temp\In", Environment.MachineName)); + + public void OutDirectoryShouldFallBackWhenFirstTestSourceIsEmpty() + { + // Simulates Android CoreCLR where Assembly.Location returns "" (before synthetic path). + var directories = new TestRunDirectories(@"C:\temp", firstTestSource: string.Empty, isAppDomainCreationDisabled: true); + directories.OutDirectory.Should().Be(@"C:\temp\Out"); + } + + public void OutDirectoryShouldFallBackWhenFirstTestSourceIsRelativePath() + { + // Simulates Android MonoVM / CoreCLR after PR #7772 where Assembly.Location + // is a relative filename like "MyTests.dll" with no directory component. + var directories = new TestRunDirectories(@"C:\temp", firstTestSource: "MyTests.dll", isAppDomainCreationDisabled: true); + directories.OutDirectory.Should().Be(@"C:\temp\Out"); + } }