From 06ed18f2aa992722501ed11baee27ab5084c8b9b Mon Sep 17 00:00:00 2001 From: Peter Collins Date: Fri, 13 Jul 2018 15:29:44 -0400 Subject: [PATCH 1/6] [Mono.Android-Tests] Ignore DotNetJavaNetworkIfaces test This test is failing rather consistently on many physical devices. See https://github.com/xamarin/xamarin-android/issues/1534 for more info. --- src/Mono.Android/Test/System.Net/NetworkInterfaces.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Mono.Android/Test/System.Net/NetworkInterfaces.cs b/src/Mono.Android/Test/System.Net/NetworkInterfaces.cs index c4d8d5eef62..959b17a3d30 100644 --- a/src/Mono.Android/Test/System.Net/NetworkInterfaces.cs +++ b/src/Mono.Android/Test/System.Net/NetworkInterfaces.cs @@ -100,7 +100,7 @@ bool HardwareAddressesAreEqual (byte[] one, byte[] two) } } - [Test] + [Test, Ignore("See https://github.com/xamarin/xamarin-android/issues/1534")] public void DotNetInterfacesShouldEqualJavaInterfaces () { List dotnetInterfaces = GetInfos (MNetworkInterface.GetAllNetworkInterfaces ()); From 54a97352e4ea12a54f2c69f1260c98a583e51c59 Mon Sep 17 00:00:00 2001 From: Peter Collins Date: Tue, 24 Jul 2018 15:39:46 -0400 Subject: [PATCH 2/6] [tests] Allow categories to be passed to new NUnit runner The new NUnit test runner currently only allows included or excluded categories to be set in code when inheriting from Xamarin.Android.UnitTests.NUnit.NUnitTestInstrumentation. There are cases where we would like to be able to conditionally set categories at test run time however. To address this, NUnitTestInsrumentation will now attempt to process certain instrumentation extras provided from the command line. Usage: ``` adb shell am instrument -e exclude InetAccess -w (PackageName)/(InstrumentationName) ``` --- .../NUnitTestInstrumentation.cs | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/tests/TestRunner.NUnit/NUnitTestInstrumentation.cs b/tests/TestRunner.NUnit/NUnitTestInstrumentation.cs index af82a84d56c..96f4139c4c7 100644 --- a/tests/TestRunner.NUnit/NUnitTestInstrumentation.cs +++ b/tests/TestRunner.NUnit/NUnitTestInstrumentation.cs @@ -36,12 +36,37 @@ void CommonInit () protected override NUnitTestRunner CreateRunner (LogWriter logger, Bundle bundle) { + SetIncludedAndExcludedCategoriesFromBundle(bundle); + return new NUnitTestRunner (Context, logger, bundle) { GCAfterEachFixture = true, TestsRootDirectory = TestsDirectory }; } + void SetIncludedAndExcludedCategoriesFromBundle(Bundle bundle) + { + string include = bundle?.GetString("include"); + if (!string.IsNullOrEmpty(include)) { + var tempList = new List(include.Split(':')); + + if (IncludedCategories != null) + tempList.AddRange(IncludedCategories); + + IncludedCategories = tempList; + } + + string exclude = bundle?.GetString("exclude"); + if (!string.IsNullOrEmpty(exclude)) { + var tempList = new List(exclude.Split(':')); + + if (ExcludedCategories != null) + tempList.AddRange(ExcludedCategories); + + ExcludedCategories = tempList; + } + } + protected override void ConfigureFilters (NUnitTestRunner runner) { base.ConfigureFilters(runner); From 84d2d2ff51a161ee248d5285acf190278fe467e4 Mon Sep 17 00:00:00 2001 From: Peter Collins Date: Tue, 24 Jul 2018 15:50:46 -0400 Subject: [PATCH 3/6] [Mono.Android-Tests] Add category to DotNetJavaNetworkIfaces test --- src/Mono.Android/Test/System.Net/NetworkInterfaces.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Mono.Android/Test/System.Net/NetworkInterfaces.cs b/src/Mono.Android/Test/System.Net/NetworkInterfaces.cs index 959b17a3d30..17176eb3123 100644 --- a/src/Mono.Android/Test/System.Net/NetworkInterfaces.cs +++ b/src/Mono.Android/Test/System.Net/NetworkInterfaces.cs @@ -100,7 +100,7 @@ bool HardwareAddressesAreEqual (byte[] one, byte[] two) } } - [Test, Ignore("See https://github.com/xamarin/xamarin-android/issues/1534")] + [Test, Category("NetworkInterfaces")] public void DotNetInterfacesShouldEqualJavaInterfaces () { List dotnetInterfaces = GetInfos (MNetworkInterface.GetAllNetworkInterfaces ()); From 7eb9aec602d0841cd54781fc508b267c93d90c46 Mon Sep 17 00:00:00 2001 From: Peter Collins Date: Tue, 24 Jul 2018 17:17:37 -0400 Subject: [PATCH 4/6] [TestRunner] Move 'extra' lookup to base TestInstrumentation class Xamarin.Android.UnitTests.TestInstrumentation can now retrieve all of the string extras included in the Bundle that is passed to OnCreate. The NUnit and XUnit flavored children of TestInstrumentation can now attempt to process category and other filter information from this collection. --- tests/TestRunner.Core/TestInstrumentation.cs | 11 ++++++ .../NUnitTestInstrumentation.cs | 34 +++++++------------ 2 files changed, 24 insertions(+), 21 deletions(-) diff --git a/tests/TestRunner.Core/TestInstrumentation.cs b/tests/TestRunner.Core/TestInstrumentation.cs index 6c586dabca5..70a9cde4dd3 100644 --- a/tests/TestRunner.Core/TestInstrumentation.cs +++ b/tests/TestRunner.Core/TestInstrumentation.cs @@ -315,6 +315,17 @@ protected virtual Assembly LoadTestAssembly (string filePath) return Assembly.LoadFrom (filePath); } + protected Dictionary GetStringExtrasFromBundle() + { + var filtersFromBundle = new Dictionary(); + foreach (var key in arguments.KeySet()) { + string value = arguments.GetString(key); + if (!string.IsNullOrEmpty(value)) + filtersFromBundle.Add(key, value); + } + return filtersFromBundle; + } + protected virtual void ConfigureFilters (TRunner runner) {} diff --git a/tests/TestRunner.NUnit/NUnitTestInstrumentation.cs b/tests/TestRunner.NUnit/NUnitTestInstrumentation.cs index 96f4139c4c7..35a81f719f9 100644 --- a/tests/TestRunner.NUnit/NUnitTestInstrumentation.cs +++ b/tests/TestRunner.NUnit/NUnitTestInstrumentation.cs @@ -36,35 +36,21 @@ void CommonInit () protected override NUnitTestRunner CreateRunner (LogWriter logger, Bundle bundle) { - SetIncludedAndExcludedCategoriesFromBundle(bundle); - return new NUnitTestRunner (Context, logger, bundle) { GCAfterEachFixture = true, TestsRootDirectory = TestsDirectory }; } - void SetIncludedAndExcludedCategoriesFromBundle(Bundle bundle) + IEnumerable GetFilterValuesFromExtras(string key) { - string include = bundle?.GetString("include"); - if (!string.IsNullOrEmpty(include)) { - var tempList = new List(include.Split(':')); - - if (IncludedCategories != null) - tempList.AddRange(IncludedCategories); - - IncludedCategories = tempList; - } - - string exclude = bundle?.GetString("exclude"); - if (!string.IsNullOrEmpty(exclude)) { - var tempList = new List(exclude.Split(':')); - - if (ExcludedCategories != null) - tempList.AddRange(ExcludedCategories); - - ExcludedCategories = tempList; + Dictionary extras = GetStringExtrasFromBundle(); + if (extras.ContainsKey(key)) { + string filterValue = extras[key]; + if (!string.IsNullOrEmpty(filterValue)) + return filterValue.Split(':'); } + return null; } protected override void ConfigureFilters (NUnitTestRunner runner) @@ -79,9 +65,15 @@ protected override void ConfigureFilters (NUnitTestRunner runner) Log.Info (LogTag, "Configuring test categories to include:"); ChainCategoryFilter (IncludedCategories, false, ref filter); + Log.Info (LogTag, "Configuring test categories to include from extras:"); + ChainCategoryFilter (GetFilterValuesFromExtras ("include"), false, ref filter); + Log.Info (LogTag, "Configuring test categories to exclude:"); ChainCategoryFilter (ExcludedCategories, true, ref filter); + Log.Info(LogTag, "Configuring test categories to exclude from extras:"); + ChainCategoryFilter (GetFilterValuesFromExtras ("exclude"), true, ref filter); + Log.Info (LogTag, "Configuring tests to exclude (by name):"); ChainTestNameFilter (ExcludedTestNames?.ToArray (), ref filter); From ed4b68dd235f9b18e00057474518f666549809c6 Mon Sep 17 00:00:00 2001 From: Jonathan Pryor Date: Thu, 26 Jul 2018 14:20:23 -0400 Subject: [PATCH 5/6] Fix formatting. --- tests/TestRunner.Core/TestInstrumentation.cs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/TestRunner.Core/TestInstrumentation.cs b/tests/TestRunner.Core/TestInstrumentation.cs index 70a9cde4dd3..2e754f82b39 100644 --- a/tests/TestRunner.Core/TestInstrumentation.cs +++ b/tests/TestRunner.Core/TestInstrumentation.cs @@ -315,13 +315,13 @@ protected virtual Assembly LoadTestAssembly (string filePath) return Assembly.LoadFrom (filePath); } - protected Dictionary GetStringExtrasFromBundle() + protected Dictionary GetStringExtrasFromBundle () { - var filtersFromBundle = new Dictionary(); - foreach (var key in arguments.KeySet()) { - string value = arguments.GetString(key); - if (!string.IsNullOrEmpty(value)) - filtersFromBundle.Add(key, value); + var filtersFromBundle = new Dictionary (); + foreach (var key in arguments.KeySet ()) { + string value = arguments.GetString (key); + if (!string.IsNullOrEmpty (value)) + filtersFromBundle.Add (key, value); } return filtersFromBundle; } From 838d6f70060492aa413a272bfb20831e266e7eb9 Mon Sep 17 00:00:00 2001 From: Jonathan Pryor Date: Thu, 26 Jul 2018 14:21:08 -0400 Subject: [PATCH 6/6] Fix formatting --- tests/TestRunner.NUnit/NUnitTestInstrumentation.cs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/TestRunner.NUnit/NUnitTestInstrumentation.cs b/tests/TestRunner.NUnit/NUnitTestInstrumentation.cs index 35a81f719f9..878cd592c74 100644 --- a/tests/TestRunner.NUnit/NUnitTestInstrumentation.cs +++ b/tests/TestRunner.NUnit/NUnitTestInstrumentation.cs @@ -42,13 +42,13 @@ protected override NUnitTestRunner CreateRunner (LogWriter logger, Bundle bundle }; } - IEnumerable GetFilterValuesFromExtras(string key) + IEnumerable GetFilterValuesFromExtras (string key) { - Dictionary extras = GetStringExtrasFromBundle(); - if (extras.ContainsKey(key)) { - string filterValue = extras[key]; - if (!string.IsNullOrEmpty(filterValue)) - return filterValue.Split(':'); + Dictionary extras = GetStringExtrasFromBundle (); + if (extras.ContainsKey (key)) { + string filterValue = extras [key]; + if (!string.IsNullOrEmpty (filterValue)) + return filterValue.Split (':'); } return null; }