Skip to content

Commit 6ae3b78

Browse files
committed
[tests] Remove XASdkDeployTests
Most of our time intensive tests are in deploy and debug scenarios, and we have some duplication there that can be cleaned up. The `XASdkDeployTests` class has been removed, and non duplicated tests from this class have been moved into `InstallAndRunTests`. The `DotNetInstallAndRun` tests have been paired down to two tests for `net7.0-android` Debug and Release. The other permutations should be covered by existing install and run tests. The `DotNetDebug` tests have been removed, as they were effectively duplicates of `ApplicationRunsWithDebuggerAndBreaks`. The `Debugger` tests have had their connection settings adjusted to try fewer times to connect but wait longer in between attempts. We will now only wait for up to 5 minutes to connect rather than ~17 minutes.
1 parent 66a0389 commit 6ae3b78

File tree

3 files changed

+131
-251
lines changed

3 files changed

+131
-251
lines changed

tests/MSBuildDeviceIntegration/Tests/DebuggingTest.cs

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ namespace Xamarin.Android.Build.Tests
1616
[Category ("UsesDevice")]
1717
public class DebuggingTest : DeviceTest
1818
{
19+
const int DEBUGGER_MAX_CONNECTIONS = 100;
20+
const int DEBUGGER_CONNECTION_TIMEOUT = 3000;
21+
1922
[TearDown]
2023
public void ClearDebugProperties ()
2124
{
@@ -242,7 +245,8 @@ public override void OnCreate ()
242245
int port = rnd.Next (10000, 20000);
243246
TestContext.Out.WriteLine ($"{port}");
244247
var args = new SoftDebuggerConnectArgs ("", IPAddress.Loopback, port) {
245-
MaxConnectionAttempts = 2000, // we need a long delay here to get a reliable connection
248+
MaxConnectionAttempts = DEBUGGER_MAX_CONNECTIONS, // we need a long delay here to get a reliable connection
249+
TimeBetweenConnectionAttempts = DEBUGGER_CONNECTION_TIMEOUT,
246250
};
247251
var startInfo = new SoftDebuggerStartInfo (args) {
248252
WorkingDirectory = Path.Combine (b.ProjectDirectory, proj.IntermediateOutputPath, "android", "assets"),
@@ -299,70 +303,87 @@ public override void OnCreate ()
299303
/* allowDeltaInstall */ false,
300304
/* user */ null,
301305
/* packageFormat */ "apk",
306+
/* useLatestSdk */ true,
307+
},
308+
new object[] {
309+
/* embedAssemblies */ true,
310+
/* fastDevType */ "Assemblies",
311+
/* allowDeltaInstall */ false,
312+
/* user */ null,
313+
/* packageFormat */ "apk",
314+
/* useLatestSdk */ false,
302315
},
303316
new object[] {
304317
/* embedAssemblies */ false,
305318
/* fastDevType */ "Assemblies",
306319
/* allowDeltaInstall */ false,
307320
/* user */ null,
308321
/* packageFormat */ "apk",
322+
/* useLatestSdk */ true,
309323
},
310324
new object[] {
311325
/* embedAssemblies */ false,
312326
/* fastDevType */ "Assemblies",
313327
/* allowDeltaInstall */ true,
314328
/* user */ null,
315329
/* packageFormat */ "apk",
330+
/* useLatestSdk */ true,
316331
},
317332
new object[] {
318333
/* embedAssemblies */ false,
319334
/* fastDevType */ "Assemblies:Dexes",
320335
/* allowDeltaInstall */ false,
321336
/* user */ null,
322337
/* packageFormat */ "apk",
338+
/* useLatestSdk */ true,
323339
},
324340
new object[] {
325341
/* embedAssemblies */ false,
326342
/* fastDevType */ "Assemblies:Dexes",
327343
/* allowDeltaInstall */ true,
328344
/* user */ null,
329345
/* packageFormat */ "apk",
346+
/* useLatestSdk */ true,
330347
},
331348
new object[] {
332349
/* embedAssemblies */ true,
333350
/* fastDevType */ "Assemblies",
334351
/* allowDeltaInstall */ false,
335352
/* user */ DeviceTest.GuestUserName,
336353
/* packageFormat */ "apk",
354+
/* useLatestSdk */ true,
337355
},
338356
new object[] {
339357
/* embedAssemblies */ false,
340358
/* fastDevType */ "Assemblies",
341359
/* allowDeltaInstall */ false,
342360
/* user */ DeviceTest.GuestUserName,
343361
/* packageFormat */ "apk",
362+
/* useLatestSdk */ true,
344363
},
345364
new object[] {
346365
/* embedAssemblies */ true,
347366
/* fastDevType */ "Assemblies",
348367
/* allowDeltaInstall */ false,
349368
/* user */ null,
350369
/* packageFormat */ "aab",
370+
/* useLatestSdk */ true,
351371
},
352372
new object[] {
353373
/* embedAssemblies */ true,
354374
/* fastDevType */ "Assemblies",
355375
/* allowDeltaInstall */ false,
356376
/* user */ DeviceTest.GuestUserName,
357377
/* packageFormat */ "aab",
378+
/* useLatestSdk */ true,
358379
},
359380
};
360381
#pragma warning restore 414
361382

362-
[Test, Category ("Debugger")]
383+
[Test, Category ("Debugger"), Category ("WearOS")]
363384
[TestCaseSource (nameof(DebuggerTestCases))]
364385
[Retry (5)]
365-
public void ApplicationRunsWithDebuggerAndBreaks (bool embedAssemblies, string fastDevType, bool allowDeltaInstall, string username, string packageFormat)
386+
public void ApplicationRunsWithDebuggerAndBreaks (bool embedAssemblies, string fastDevType, bool allowDeltaInstall, string username, string packageFormat, bool useLatestSdk)
366387
{
367388
AssertCommercialBuild ();
368389
SwitchUser ();
@@ -405,6 +426,9 @@ public Foo ()
405426
EmbedAssembliesIntoApk = embedAssemblies,
406427
AndroidFastDeploymentType = fastDevType
407428
};
429+
if (!useLatestSdk) {
430+
app.TargetFramework = "net7.0-android";
431+
}
408432
app.SetProperty ("AndroidPackageFormat", packageFormat);
409433
app.MainPage = app.MainPage.Replace ("InitializeComponent ();", "InitializeComponent (); new Foo ();");
410434
app.AddReference (lib);
@@ -465,7 +489,8 @@ public Foo ()
465489
int port = rnd.Next (10000, 20000);
466490
TestContext.Out.WriteLine ($"{port}");
467491
var args = new SoftDebuggerConnectArgs ("", IPAddress.Loopback, port) {
468-
MaxConnectionAttempts = 2000,
492+
MaxConnectionAttempts = DEBUGGER_MAX_CONNECTIONS,
493+
TimeBetweenConnectionAttempts = DEBUGGER_CONNECTION_TIMEOUT,
469494
};
470495
var startInfo = new SoftDebuggerStartInfo (args) {
471496
WorkingDirectory = Path.Combine (appBuilder.ProjectDirectory, app.IntermediateOutputPath, "android", "assets"),

tests/MSBuildDeviceIntegration/Tests/InstallAndRunTests.cs

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Collections.Generic;
33
using System.IO;
44
using System.Linq;
5+
using System.Text;
56
using System.Text.RegularExpressions;
67
using System.Xml.Linq;
78
using System.Xml.XPath;
@@ -1137,5 +1138,106 @@ public void CheckResouceIsOverridden ([Values (true, false)] bool useAapt2)
11371138
}
11381139
}
11391140

1141+
[Test]
1142+
[Category ("WearOS")]
1143+
public void DotNetInstallAndRunPreviousSdk ([Values (false, true)] bool isRelease)
1144+
{
1145+
var proj = new XamarinFormsAndroidApplicationProject () {
1146+
TargetFramework = "net7.0-android",
1147+
IsRelease = isRelease,
1148+
EnableDefaultItems = true,
1149+
};
1150+
1151+
var builder = CreateApkBuilder ();
1152+
Assert.IsTrue (builder.Build (proj), "`dotnet build` should succeed");
1153+
RunProjectAndAssert (proj, builder);
1154+
1155+
WaitForPermissionActivity (Path.Combine (Root, builder.ProjectDirectory, "permission-logcat.log"));
1156+
bool didLaunch = WaitForActivityToStart (proj.PackageName, "MainActivity",
1157+
Path.Combine (Root, builder.ProjectDirectory, "logcat.log"), 30);
1158+
Assert.IsTrue(didLaunch, "Activity should have started.");
1159+
}
1160+
1161+
[Test]
1162+
public void TypeAndMemberRemapping ([Values (false, true)] bool isRelease)
1163+
{
1164+
var proj = new XamarinAndroidApplicationProject () {
1165+
IsRelease = isRelease,
1166+
EnableDefaultItems = true,
1167+
OtherBuildItems = {
1168+
new AndroidItem._AndroidRemapMembers ("RemapActivity.xml") {
1169+
Encoding = Encoding.UTF8,
1170+
TextContent = () => ResourceData.RemapActivityXml,
1171+
},
1172+
new AndroidItem.AndroidJavaSource ("RemapActivity.java") {
1173+
Encoding = new UTF8Encoding (encoderShouldEmitUTF8Identifier: false),
1174+
TextContent = () => ResourceData.RemapActivityJava,
1175+
Metadata = {
1176+
{ "Bind", "True" },
1177+
},
1178+
},
1179+
},
1180+
};
1181+
proj.MainActivity = proj.DefaultMainActivity.Replace (": Activity", ": global::Example.RemapActivity");
1182+
var builder = CreateApkBuilder ();
1183+
Assert.IsTrue (builder.Build (proj), "`dotnet build` should succeed");
1184+
RunProjectAndAssert (proj, builder);
1185+
var appStartupLogcatFile = Path.Combine (Root, builder.ProjectDirectory, "logcat.log");
1186+
bool didLaunch = WaitForActivityToStart (proj.PackageName, "MainActivity", appStartupLogcatFile);
1187+
Assert.IsTrue (didLaunch, "MainActivity should have launched!");
1188+
var logcatOutput = File.ReadAllText (appStartupLogcatFile);
1189+
1190+
StringAssert.Contains (
1191+
"RemapActivity.onMyCreate() invoked!",
1192+
logcatOutput,
1193+
"Activity.onCreate() wasn't remapped to RemapActivity.onMyCreate()!"
1194+
);
1195+
StringAssert.Contains (
1196+
"ViewHelper.mySetOnClickListener() invoked!",
1197+
logcatOutput,
1198+
"View.setOnClickListener() wasn't remapped to ViewHelper.mySetOnClickListener()!"
1199+
);
1200+
}
1201+
1202+
[Test]
1203+
public void SupportDesugaringStaticInterfaceMethods ()
1204+
{
1205+
var proj = new XamarinAndroidApplicationProject () {
1206+
IsRelease = true,
1207+
EnableDefaultItems = true,
1208+
OtherBuildItems = {
1209+
new AndroidItem.AndroidJavaSource ("StaticMethodsInterface.java") {
1210+
Encoding = new UTF8Encoding (encoderShouldEmitUTF8Identifier: false),
1211+
TextContent = () => ResourceData.IdmStaticMethodsInterface,
1212+
Metadata = {
1213+
{ "Bind", "True" },
1214+
},
1215+
},
1216+
},
1217+
};
1218+
1219+
// Note: To properly test, Desugaring must be *enabled*, which requires that
1220+
// `$(SupportedOSPlatformVersion)` be *less than* 23. 21 is currently the default,
1221+
// but set this explicitly anyway just so that this implicit requirement is explicit.
1222+
proj.SupportedOSPlatformVersion = "21";
1223+
1224+
proj.MainActivity = proj.DefaultMainActivity.Replace ("//${AFTER_ONCREATE}", @"
1225+
Console.WriteLine ($""# jonp static interface default method invocation; IStaticMethodsInterface.Value={Example.IStaticMethodsInterface.Value}"");
1226+
");
1227+
var builder = CreateApkBuilder ();
1228+
Assert.IsTrue (builder.Build (proj), "`dotnet build` should succeed");
1229+
RunProjectAndAssert (proj, builder);
1230+
var appStartupLogcatFile = Path.Combine (Root, builder.ProjectDirectory, "logcat.log");
1231+
bool didLaunch = WaitForActivityToStart (proj.PackageName, "MainActivity", appStartupLogcatFile);
1232+
Assert.IsTrue (didLaunch, "MainActivity should have launched!");
1233+
var logcatOutput = File.ReadAllText (appStartupLogcatFile);
1234+
1235+
StringAssert.Contains (
1236+
"IStaticMethodsInterface.Value=3",
1237+
logcatOutput,
1238+
"Was IStaticMethodsInterface.Value executed?"
1239+
);
1240+
}
1241+
11401242
}
11411243
}

0 commit comments

Comments
 (0)