diff --git a/Documentation/DevelopmentTips.md b/Documentation/DevelopmentTips.md index 980f6c20a7c..1c4bdae1956 100644 --- a/Documentation/DevelopmentTips.md +++ b/Documentation/DevelopmentTips.md @@ -178,6 +178,20 @@ For example: $ tools/scripts/xabuild /t:DeployTestApks tests/locales/Xamarin.Android.Locale-Tests/Xamarin.Android.Locale-Tests.csproj $ tools/scripts/xabuild /t:RunTestApks tests/locales/Xamarin.Android.Locale-Tests/Xamarin.Android.Locale-Tests.csproj +## Running `.apk` Projects with Include/Exclude + +For example, to exclude tests that use the internet (`InetAccess` category): + + $ make run-apk-tests EXCLUDECATEGORIES=InetAccess + +On Windows: + + $ msbuild Xamarin.Android.sln /t:RunApkTests /p:ExcludeCategories=InetAccess + +`INCLUDECATEGORIES` and `IncludeCategories` function in the same fashion. + +To specify multiple categories, delimit each category with a `:` character. The `:` delimiter works well with both `MSBuild` properties and `make` variables. + ### Running A Single Test Fixture A single NUnit *Test Fixture* -- a class with the `[TestFixture]` diff --git a/build-tools/scripts/TestApks.targets b/build-tools/scripts/TestApks.targets index 699d99e61a6..e81751db628 100644 --- a/build-tools/scripts/TestApks.targets +++ b/build-tools/scripts/TestApks.targets @@ -152,12 +152,17 @@ + + <_IncludeCategories Condition=" '$(IncludeCategories)' != '' ">include=$(IncludeCategories) + <_ExcludeCategories Condition=" '$(ExcludeCategories)' != '' ">exclude=$(ExcludeCategories) + diff --git a/src/Mono.Android/Test/System.Net/ProxyTest.cs b/src/Mono.Android/Test/System.Net/ProxyTest.cs index 0887dfce7a0..efe746c7cee 100644 --- a/src/Mono.Android/Test/System.Net/ProxyTest.cs +++ b/src/Mono.Android/Test/System.Net/ProxyTest.cs @@ -6,7 +6,7 @@ namespace System.NetTests { - [TestFixture] + [TestFixture, Category ("InetAccess")] public class ProxyTest { // https://bugzilla.xamarin.com/show_bug.cgi?id=14968 diff --git a/src/Mono.Android/Test/System.Net/SslTest.cs b/src/Mono.Android/Test/System.Net/SslTest.cs index 1236a4f5410..b560a7e7a6d 100644 --- a/src/Mono.Android/Test/System.Net/SslTest.cs +++ b/src/Mono.Android/Test/System.Net/SslTest.cs @@ -10,7 +10,7 @@ namespace System.NetTests { - [TestFixture] + [TestFixture, Category ("InetAccess")] public class SslTest { // https://xamarin.desk.com/agent/case/35534 diff --git a/src/Mono.Android/Test/Xamarin.Android.Net/AndroidClientHandlerTests.cs b/src/Mono.Android/Test/Xamarin.Android.Net/AndroidClientHandlerTests.cs index 7def270ec0b..1f03dc4bc37 100644 --- a/src/Mono.Android/Test/Xamarin.Android.Net/AndroidClientHandlerTests.cs +++ b/src/Mono.Android/Test/Xamarin.Android.Net/AndroidClientHandlerTests.cs @@ -39,10 +39,10 @@ using Android.OS; namespace Xamarin.Android.NetTests { - + [Category("InetAccess")] public abstract class HttpClientHandlerTestBase { - protected abstract HttpClientHandler CreateHandler (); + protected abstract HttpClientHandler CreateHandler (); class Proxy : IWebProxy { diff --git a/src/Mono.Android/Test/Xamarin.Android.Net/HttpClientIntegrationTests.cs b/src/Mono.Android/Test/Xamarin.Android.Net/HttpClientIntegrationTests.cs index 089d3a3f200..15aa2b93171 100644 --- a/src/Mono.Android/Test/Xamarin.Android.Net/HttpClientIntegrationTests.cs +++ b/src/Mono.Android/Test/Xamarin.Android.Net/HttpClientIntegrationTests.cs @@ -38,7 +38,7 @@ using System.IO; namespace Xamarin.Android.NetTests { - + [Category ("InetAccess")] public abstract class HttpClientIntegrationTestBase { protected abstract HttpClientHandler CreateHandler (); diff --git a/src/Xamarin.Android.NUnitLite/Gui/Activities/TestSuiteActivity.cs b/src/Xamarin.Android.NUnitLite/Gui/Activities/TestSuiteActivity.cs index fd70cbdbd7d..20c9e4abf91 100644 --- a/src/Xamarin.Android.NUnitLite/Gui/Activities/TestSuiteActivity.cs +++ b/src/Xamarin.Android.NUnitLite/Gui/Activities/TestSuiteActivity.cs @@ -103,12 +103,12 @@ protected override void OnResume () protected virtual IEnumerable GetIncludedCategories () { - return null; + yield break; } protected virtual IEnumerable GetExcludedCategories () { - return null; + yield break; } // Subclasses can override this method to update the test filtering that the runner will use. diff --git a/src/Xamarin.Android.NUnitLite/Gui/AndroidRunner.cs b/src/Xamarin.Android.NUnitLite/Gui/AndroidRunner.cs index e2ccea531ce..e9b7f05facb 100644 --- a/src/Xamarin.Android.NUnitLite/Gui/AndroidRunner.cs +++ b/src/Xamarin.Android.NUnitLite/Gui/AndroidRunner.cs @@ -389,7 +389,8 @@ static void ChainCategoryFilter (IEnumerable categories, bool negate, r gotCategories = true; } - chain = new AndFilter (chain, negate ? (TestFilter)new NotFilter (filter) : (TestFilter)filter); + if (gotCategories) + chain = new AndFilter (chain, negate ? (TestFilter)new NotFilter (filter) : (TestFilter)filter); } if (!gotCategories) diff --git a/src/Xamarin.Android.NUnitLite/Gui/Instrumentations/TestSuiteInstrumentation.cs b/src/Xamarin.Android.NUnitLite/Gui/Instrumentations/TestSuiteInstrumentation.cs index f46a06205e7..53e18dcd946 100644 --- a/src/Xamarin.Android.NUnitLite/Gui/Instrumentations/TestSuiteInstrumentation.cs +++ b/src/Xamarin.Android.NUnitLite/Gui/Instrumentations/TestSuiteInstrumentation.cs @@ -146,12 +146,22 @@ protected void AddTest (Assembly assembly) protected virtual IEnumerable GetIncludedCategories () { - return null; + string include = arguments?.GetString ("include"); + if (!string.IsNullOrEmpty (include)) { + foreach (var category in include.Split (':')) { + yield return category; + } + } } protected virtual IEnumerable GetExcludedCategories () { - return null; + string exclude = arguments?.GetString ("exclude"); + if (!string.IsNullOrEmpty (exclude)) { + foreach (var category in exclude.Split (':')) { + yield return category; + } + } } protected virtual void UpdateFilter () diff --git a/tests/Xamarin.Android.Bcl-Tests/TestInstrumentation.cs b/tests/Xamarin.Android.Bcl-Tests/TestInstrumentation.cs index 127de412474..5d30e023d04 100644 --- a/tests/Xamarin.Android.Bcl-Tests/TestInstrumentation.cs +++ b/tests/Xamarin.Android.Bcl-Tests/TestInstrumentation.cs @@ -29,7 +29,12 @@ protected override void AddTests () protected override IEnumerable GetExcludedCategories () { - return App.GetExcludedCategories (); + foreach (var category in base.GetExcludedCategories ()) { + yield return category; + } + foreach (var category in App.GetExcludedCategories ()) { + yield return category; + } } protected override void UpdateFilter ()