Skip to content

Commit bb2c376

Browse files
authored
[tests] Enable more tests to run on all 3 runtimes, part 6 (#10595)
This parameterizes tests to run across different Android runtimes and refactoring the way build properties are handled for NativeAOT scenarios. **Test Parameterization and Runtime Handling** * Refactored all test methods in `AssetPackTests.cs` and `CodeBehindTests.cs` to use the `[Values]` attribute for both `isRelease` and `AndroidRuntime runtime` parameters. * Added logic to skip unsupported runtime/configuration combinations using `IgnoreUnsupportedConfiguration`, preventing test failures on invalid configurations. **Build Properties and Warning Management** * Refactored `GetBuildProperties` to dynamically construct the `NoWarn` property, including additional IL and XA warnings when running NativeAOT tests on CI, improving test reliability and output clarity. * Updated test logic to conditionally assert zero warnings for non-NativeAOT runs, accommodating known issues with NativeAOT builds. **Test Infrastructure Improvements** * Enhanced the `TestProjectInfo` class to track the selected runtime and test root directory, supporting better test isolation and reporting. * Updated method signatures and invocations to consistently pass the `runtime` parameter through all test helpers and runners.
1 parent 9d9fde5 commit bb2c376

File tree

6 files changed

+198
-97
lines changed

6 files changed

+198
-97
lines changed

src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/AssetPackTests.cs

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Text;
55
using Xamarin.Android.Tasks;
66
using Xamarin.ProjectTools;
7+
using System.Collections.Generic;
78

89
namespace Xamarin.Android.Build.Tests
910
{
@@ -13,8 +14,11 @@ public class AssetPackTests : BaseTest
1314
{
1415
[Test]
1516
[Category ("SmokeTests")]
16-
public void BuildLibraryWithAssetPack ([Values (true, false)] bool isRelease)
17+
public void BuildLibraryWithAssetPack ([Values] bool isRelease, [Values] AndroidRuntime runtime)
1718
{
19+
if (IgnoreUnsupportedConfiguration (runtime, release: isRelease)) {
20+
return;
21+
}
1822
var path = Path.Combine ("temp", TestName);
1923
var lib = new XamarinAndroidLibraryProject {
2024
IsRelease = isRelease,
@@ -26,6 +30,7 @@ public void BuildLibraryWithAssetPack ([Values (true, false)] bool isRelease)
2630
},
2731
}
2832
};
33+
lib.SetRuntime (runtime);
2934
using (var builder = CreateDllBuilder (Path.Combine (path, lib.ProjectName))) {
3035
builder.ThrowOnBuildFailure = false;
3136
Assert.IsFalse (builder.Build (lib), $"{lib.ProjectName} should fail.");
@@ -36,13 +41,11 @@ public void BuildLibraryWithAssetPack ([Values (true, false)] bool isRelease)
3641

3742
[Test]
3843
[Category ("SmokeTests")]
39-
[TestCase (false, AndroidRuntime.MonoVM)]
40-
[TestCase (true, AndroidRuntime.MonoVM)]
41-
[TestCase (false, AndroidRuntime.CoreCLR)]
42-
[TestCase (true, AndroidRuntime.CoreCLR)]
43-
[TestCase (true, AndroidRuntime.NativeAOT)]
44-
public void BuildApplicationWithAssetPackThatHasInvalidName (bool isRelease, AndroidRuntime runtime)
44+
public void BuildApplicationWithAssetPackThatHasInvalidName ([Values] bool isRelease, [Values] AndroidRuntime runtime)
4545
{
46+
if (IgnoreUnsupportedConfiguration (runtime, release: isRelease)) {
47+
return;
48+
}
4649
var path = Path.Combine ("temp", TestName);
4750
var app = new XamarinAndroidApplicationProject {
4851
IsRelease = isRelease,
@@ -66,13 +69,11 @@ public void BuildApplicationWithAssetPackThatHasInvalidName (bool isRelease, And
6669

6770
[Test]
6871
[Category ("SmokeTests")]
69-
[TestCase (false, AndroidRuntime.MonoVM)]
70-
[TestCase (true, AndroidRuntime.MonoVM)]
71-
[TestCase (false, AndroidRuntime.CoreCLR)]
72-
[TestCase (true, AndroidRuntime.CoreCLR)]
73-
[TestCase (true, AndroidRuntime.NativeAOT)]
74-
public void BuildApplicationWithAssetPackOutsideProjectDirectory (bool isRelease, AndroidRuntime runtime)
72+
public void BuildApplicationWithAssetPackOutsideProjectDirectory ([Values] bool isRelease, [Values] AndroidRuntime runtime)
7573
{
74+
if (IgnoreUnsupportedConfiguration (runtime, release: isRelease)) {
75+
return;
76+
}
7677
var path = Path.Combine ("temp", TestName);
7778
var app = new XamarinAndroidApplicationProject {
7879
ProjectName = "MyApp",
@@ -117,13 +118,11 @@ public void BuildApplicationWithAssetPackOutsideProjectDirectory (bool isRelease
117118

118119
[Test]
119120
[Category ("SmokeTests")]
120-
[TestCase (false, AndroidRuntime.MonoVM)]
121-
[TestCase (true, AndroidRuntime.MonoVM)]
122-
[TestCase (false, AndroidRuntime.CoreCLR)]
123-
[TestCase (true, AndroidRuntime.CoreCLR)]
124-
[TestCase (true, AndroidRuntime.NativeAOT)]
125-
public void BuildApplicationWithAssetPackOverrides (bool isRelease, AndroidRuntime runtime)
121+
public void BuildApplicationWithAssetPackOverrides ([Values] bool isRelease, [Values] AndroidRuntime runtime)
126122
{
123+
if (IgnoreUnsupportedConfiguration (runtime, release: isRelease)) {
124+
return;
125+
}
127126
var path = Path.Combine ("temp", TestName);
128127
var app = new XamarinAndroidApplicationProject {
129128
ProjectName = "MyApp",
@@ -161,13 +160,11 @@ public void BuildApplicationWithAssetPackOverrides (bool isRelease, AndroidRunti
161160

162161
[Test]
163162
[Category ("SmokeTests")]
164-
[TestCase (false, AndroidRuntime.MonoVM)]
165-
[TestCase (true, AndroidRuntime.MonoVM)]
166-
[TestCase (false, AndroidRuntime.CoreCLR)]
167-
[TestCase (true, AndroidRuntime.CoreCLR)]
168-
[TestCase (true, AndroidRuntime.NativeAOT)]
169-
public void BuildApplicationWithAssetPack (bool isRelease, AndroidRuntime runtime)
163+
public void BuildApplicationWithAssetPack ([Values] bool isRelease, [Values] AndroidRuntime runtime)
170164
{
165+
if (IgnoreUnsupportedConfiguration (runtime, release: isRelease)) {
166+
return;
167+
}
171168
var path = Path.Combine ("temp", TestName);
172169
var asset3 = new AndroidItem.AndroidAsset ("Assets\\asset3.txt") {
173170
TextContent = () => "Asset3",

0 commit comments

Comments
 (0)