From 9a9595a95068f24de74178667821b8287e349036 Mon Sep 17 00:00:00 2001 From: Jonathan Peppers Date: Mon, 13 Jul 2026 08:47:21 -0500 Subject: [PATCH] [templates] Update androidtest MSTest Update the androidtest template to MSTest 4.3.2. Exercise dotnet test with both the stable template dependency and the nightly build dependency. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: b7c547f6-a8ce-4e27-b18f-05a24fb1d5e7 --- .../androidtest/AndroidTest1.csproj | 2 +- .../Tests/InstallAndRunTests.cs | 46 +++++++++++-------- 2 files changed, 27 insertions(+), 21 deletions(-) diff --git a/src/Microsoft.Android.Templates/androidtest/AndroidTest1.csproj b/src/Microsoft.Android.Templates/androidtest/AndroidTest1.csproj index b1fe0091ac2..f0c5dbe9df5 100644 --- a/src/Microsoft.Android.Templates/androidtest/AndroidTest1.csproj +++ b/src/Microsoft.Android.Templates/androidtest/AndroidTest1.csproj @@ -18,7 +18,7 @@ - + diff --git a/tests/MSBuildDeviceIntegration/Tests/InstallAndRunTests.cs b/tests/MSBuildDeviceIntegration/Tests/InstallAndRunTests.cs index d9aff0ceac0..0fd71db7806 100644 --- a/tests/MSBuildDeviceIntegration/Tests/InstallAndRunTests.cs +++ b/tests/MSBuildDeviceIntegration/Tests/InstallAndRunTests.cs @@ -2480,12 +2480,19 @@ public void StartAndroidActivityRespectsAndroidDeviceUserId () "The 'am start' command should contain '--user 0' when AndroidDeviceUserId is set."); } + public enum MSTestPackageChannel + { + Stable, + Nightly, + } + [Test] - [TestCase ("run", AndroidRuntime.CoreCLR)] - [TestCase ("test", AndroidRuntime.CoreCLR)] - public void DotNetNewAndroidTest (string mode, AndroidRuntime runtime) + [TestCase ("run", MSTestPackageChannel.Nightly)] + [TestCase ("test", MSTestPackageChannel.Stable)] + [TestCase ("test", MSTestPackageChannel.Nightly)] + public void DotNetNewAndroidTest (string mode, MSTestPackageChannel msTestPackageChannel) { - var templateName = $"DotNetNewAndroidTest_{mode}_{runtime}"; + var templateName = $"DotNetNewAndroidTest_{mode}_{msTestPackageChannel}"; var projectDirectory = Path.Combine (Root, "temp", templateName); if (Directory.Exists (projectDirectory)) Directory.Delete (projectDirectory, true); @@ -2494,22 +2501,21 @@ public void DotNetNewAndroidTest (string mode, AndroidRuntime runtime) var dotnet = new DotNetCLI (Path.Combine (projectDirectory, $"{templateName}.csproj")); Assert.IsTrue (dotnet.New ("androidtest"), "`dotnet new androidtest` should succeed"); - // Override the MSTest version from the template with the version used by our build - var msTestVersion = GetAssemblyMetadataValue ("MSTestPackageVersion"); - var csprojPath = Path.Combine (projectDirectory, $"{templateName}.csproj"); - var doc = XDocument.Load (csprojPath); - var ns = doc.Root?.Name.Namespace ?? XNamespace.None; - var msTestRef = doc.Descendants (ns + "PackageReference") - .FirstOrDefault (e => e.Attribute ("Include")?.Value == "MSTest"); - Assert.IsNotNull (msTestRef, "MSTest PackageReference should exist in the generated project"); - msTestRef.SetAttributeValue ("Version", msTestVersion); - doc.Save (csprojPath); - - bool useMonoRuntime = runtime == AndroidRuntime.MonoVM; - var buildParameters = new List { - $"UseMonoRuntime={useMonoRuntime}", - "RestoreAdditionalProjectSources=https://pkgs.dev.azure.com/dnceng/public/_packaging/test-tools/nuget/v3/index.json", - }; + var buildParameters = new List (); + + if (msTestPackageChannel == MSTestPackageChannel.Nightly) { + // Override the stable template version with the version used by our build. + var msTestVersion = GetAssemblyMetadataValue ("MSTestPackageVersion"); + var csprojPath = Path.Combine (projectDirectory, $"{templateName}.csproj"); + var doc = XDocument.Load (csprojPath); + var ns = doc.Root?.Name.Namespace ?? XNamespace.None; + var msTestRef = doc.Descendants (ns + "PackageReference") + .FirstOrDefault (e => e.Attribute ("Include")?.Value == "MSTest"); + Assert.IsNotNull (msTestRef, "MSTest PackageReference should exist in the generated project"); + msTestRef.SetAttributeValue ("Version", msTestVersion); + doc.Save (csprojPath); + buildParameters.Add ("RestoreAdditionalProjectSources=https://pkgs.dev.azure.com/dnceng/public/_packaging/test-tools/nuget/v3/index.json"); + } // Build and assert 0 warnings Assert.IsTrue (dotnet.Build (parameters: buildParameters.ToArray ()), "`dotnet build` should succeed");