-
Notifications
You must be signed in to change notification settings - Fork 536
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[tests] option to include/exclude categories from Test APKs #1024
[tests] option to include/exclude categories from Test APKs #1024
Conversation
@jonathanpeppers, |
To match Mono, I need to change the category to |
47bc5b7
to
560fcb2
Compare
I'm not sure I'd suggest Additionally, please update Finally, as this updates e.g. protected override IEnumerable<string> GetExcludedCategories ()
{
return App.GetExcludedCategories ();
} We'll want protected override IEnumerable<string> GetExcludedCategories ()
{
var external = base.GetExcludedCategories ();
return external != null
? external.Concat (App.GetExcludedCategories ())
: App.GetExternalCategories ();
} Writing the above makes me think that we should also update the semantics of |
560fcb2
to
3ca309c
Compare
} | ||
|
||
protected virtual IEnumerable <string> GetExcludedCategories () | ||
{ | ||
return null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of returning null, these will be the equivalent of yield break
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TestSuiteActivity
should also be updated to not return null
.
@@ -381,7 +381,7 @@ internal void AddTestFilters (IEnumerable<string> included, IEnumerable<string> | |||
static void ChainCategoryFilter (IEnumerable <string> categories, bool negate, ref TestFilter chain) | |||
{ | |||
bool gotCategories = false; | |||
if (categories != null) { | |||
if (categories != null && categories.Any ()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to check Any()
, because an empty IEnumerable
should also be skipped
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should arguably be skipped, but it means that categories
will be enumerated multiple times, which is potentially problematic.
It's probably better to not use the .Any()
, and have an alternate check.
3ca309c
to
c208c43
Compare
build-tools/scripts/TestApks.targets
Outdated
@@ -152,12 +152,17 @@ | |||
|
|||
<Target Name="RunTestApks" | |||
Condition=" '@(TestApk)' != '' "> | |||
<PropertyGroup> | |||
<_InstrumentationArguments Condition=" '$(IncludeCategories)' != '' ">include=$(IncludeCategories)</_InstrumentationArguments> | |||
<_InstrumentationArguments Condition=" '$(ExcludeCategories)' != '' ">exclude=$(ExcludeCategories)</_InstrumentationArguments> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This construct means that you can't use both $(IncludeCategories)
and $(ExcludeCategories)
at the same time:
msbuild Xamarin.Android.sln /t:RunApkTests /p:ExcludeCategories=InetAccess /p:IncludeCategories=Whatever
I'm not immediately sure how useful such a thing is, but if we're going to have $(IncludeCategories)
at all, then we should sensibly support both...
I think that this will work sanely:
<PropertyGroup>
<_IncludeCats Condition=" '$(IncludeCategories)' != '' ">include=$(IncludeCategories)</_IncludeCats>
<_ExcludeCats Condition=" '$(ExcludeCategories)' != '' ">exclude=$(ExcludeCategories)</_ExcludeCats >
</PropertyGroup>
...
<RunInstrumentationTests
InstrumentationArguments="$(_IncludeCats);$(_ExcludeCats)"
...
/>
c208c43
to
e58c5c5
Compare
<RunInstrumentationTests | ||
Condition=" '%(TestApk.InstrumentationType)' != ''" | ||
AdbTarget="$(_AdbTarget)" | ||
AdbOptions="$(AdbOptions)" | ||
Component="%(TestApk.Package)/%(TestApk.InstrumentationType)" | ||
NUnit2TestResultsFile="%(TestApk.ResultsPath)" | ||
InstrumentationArguments="$(_IncludeCategories);$(_ExcludeCategories)" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, this is better: it lets you specify include/exclude at the same time.
My example that worked:
make run-apk-tests INCLUDECATEGORIES=InetAccess EXCLUDECATEGORIES=Bologna
Of course no category is named Bologna
, but the command in the log was:
Tool /Users/jonathanpeppers/android-toolchain/sdk/platform-tools/adb execution started with arguments: shell am instrument -e "include" "InetAccess" -e "exclude" "Bologna" -w "Mono.Android_Tests/xamarin.android.runtimetests.TestInstrumentation"
Documentation/DevelopmentTips.md
Outdated
|
||
`INCLUDECATEGORIES` and `IncludeCategories` function in the same fashion. | ||
|
||
To specify multiple categories, delimit each category with a `,` character. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should ,
be used as a delimiter?
The problem is, it can't be used on the command-line:
$ msbuild /nologo Xamarin.Android.sln /t:RunApkTests /p:ExcludeCategories=InetAccess,Bologna
MSBUILD : error MSB1006: Property is not valid.
Switch: Bologna
For switch syntax, type "MSBuild /help"
This is why :
was chosen as the separator char for e.g. $(AndroidSupportedTargetJitAbis)
, as it can be specified on the command-line.
1167300
to
c7c57a0
Compare
In some QA needs to run tests on devices without a network connection, so an option to disable tests that rely on the network in Mono.Android-Tests is needed. NUnit has the option to include or exclude tests based on the `CategoryAttribute`. Various tests were decorated with `[Category("InetAccess")]` that appeared to use the internet. To verify this works, I ran the tests with my internet disabled. The test run for Mono.Android-Tests went down from 106 to 84 tests, with no failures. To exclude a category, on Windows: msbuild Xamarin.Android.sln /t:RunApkTests /p:ExcludeCategories=InetAccess On MacOS/Linux: make run-apk-tests EXCLUDECATEGORIES=InetAccess If you want to specify multiple categories, use `:` (colon) to delimit each category. This delimiter is used for various values throughout Xamarin.Android's build because it works well from the command line for both MSBuild and make. I also added the option specify `Include` as well, but it isn't particularly useful for this case.
c7c57a0
to
661f0cf
Compare
Fixes: #7234 Changes: dotnet/java-interop@a5756ca...e31d9c6 * dotnet/java-interop@e31d9c62: Context: #7285 (comment) (#1029) * dotnet/java-interop@d3ea180c: [generator] Add support for `[ObsoletedOSPlatform]` (#1026) * dotnet/java-interop@6d1ae4ee: [generator] Remove [Obsolete] style compatibility hacks. (#1025) * dotnet/java-interop@440c05ee: [generator] Refactor logic for applying [Obsolete] attributes (#1024) * dotnet/java-interop@9b1d3ab7: [Localization] Import translated resx files (#1018) `generator` can now emit `[ObsoletedOSPlatformAttribute]`. Requires: - Update `Mono.Android.targets` to pass `lang-feature=obsoleted-platform-attributes` to `generator` when building for .NET 7+ - Update `acceptable-breakages-vReference-net7.0.txt` to account for removing existing `[Obsolete]` attributes in favor of the new ones, for .NET 7+ only
Fixes: #7234 Changes: dotnet/java-interop@a5756ca...e31d9c6 * dotnet/java-interop@e31d9c62: Context: #7285 (comment) (#1029) * dotnet/java-interop@d3ea180c: [generator] Add support for `[ObsoletedOSPlatform]` (#1026) * dotnet/java-interop@6d1ae4ee: [generator] Remove [Obsolete] style compatibility hacks. (#1025) * dotnet/java-interop@440c05ee: [generator] Refactor logic for applying [Obsolete] attributes (#1024) * dotnet/java-interop@9b1d3ab7: [Localization] Import translated resx files (#1018) `generator` can now emit `[ObsoletedOSPlatformAttribute]`. Requires: - Update `Mono.Android.targets` to pass `lang-feature=obsoleted-platform-attributes` to `generator` when building for .NET 7+ - Update `acceptable-breakages-vReference-net7.0.txt` to account for removing existing `[Obsolete]` attributes in favor of the new ones, for .NET 7+ only
In some QA needs to run tests on devices without a network connection,
so an option to disable tests that rely on the network in Mono.Android-Tests
is needed.
NUnit has the option to include or exclude tests based on the
CategoryAttribute
. Various tests were decorated with[Category("InetAccess")]
that appeared to use the internet. To verifythis works, I ran the tests with my internet disabled. The test run for
Mono.Android-Tests went down from 106 to 84 tests, with no failures.
To exclude a category, on Windows:
On MacOS/Linux:
If you want to specify multiple categories, use
:
(colon) to delimiteach category. This delimiter is used for various values throughout
Xamarin.Android's build because it works well from the command line for both
MSBuild and make.
I also added the option specify
Include
as well, but it isn't particularlyuseful for this case.