Skip to content
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

[One .NET] Add Microsoft.Android-Tests unit tests #5250

Merged
merged 1 commit into from
Nov 16, 2020

Conversation

pjcollins
Copy link
Member

@pjcollins pjcollins commented Oct 29, 2020

A new version of Mono.Android-Tests has been added to run against the
.NET 6 SDK:

  • tests/Mono.Android-Tests/Runtime-Microsoft.Android.Sdk/Mono.Android.NET-Tests.csproj

To support this, new .NET .csproj files have been added alongside all of
the existing legacy Xamarin.Android unit test library projects. These
projects target net5.0-android and build against our .NET 6 SDK:

  • src/Mono.Android/Test/Java.Interop-Tests/Java.Interop-Tests.NET.csproj
  • src/Mono.Android/Test/Mono.Android-Test.Library/Mono.Android-Test.Library.NET.csproj
  • src/Xamarin.Android.NUnitLite/Xamarin.Android.NUnitLite.NET.csproj
  • tests/TestRunner.Core/TestRunner.Core.NET.csproj
  • tests/TestRunner.NUnit/TestRunner.NUnit.NET.csproj

The _CreateAar target was being skipped for the new Java.Interop-Tests.NET
project, as it had no inputs. As a result, the Mono.Android-Test-classes.jar
file required by these tests was not being included in the application project.
To fix this, I've added @(AndroidJavaLibrary) to @(_CreateAarInputs) so that
these items will also be considered as inputs for this target/task.

All tests which have been ignored are tied back to one of the following issues:

@pjcollins pjcollins force-pushed the net5-runtime-tests branch 8 times, most recently from 73bb0da to 8a3bc77 Compare November 2, 2020 22:55
@pjcollins pjcollins force-pushed the net5-runtime-tests branch 3 times, most recently from 71dd3c6 to 8b367fd Compare November 6, 2020 17:21
@pjcollins pjcollins marked this pull request as ready for review November 6, 2020 17:37
@pjcollins pjcollins requested a review from radekdoulik November 6, 2020 17:38
@@ -453,7 +454,9 @@ public ContainsExportedMethods ()
Constructed = true;
}

#if !NET // https://github.com/xamarin/xamarin-android/issues/5265
[Export]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it should be enough to disable the CreateTypeWithExportedMethods test on dotnet?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nm. The build error is happening even when Mono.Android.Export is referenced. I will look at how to fix #5265

@@ -0,0 +1,148 @@
<Project Sdk="Microsoft.NET.Sdk" >
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this file also be added to Xamarin.Android-Tests.sln?

<Import Project="Microsoft.Android-Tests.projitems" />
<Import Project="..\..\build-tools\scripts\TestApks.targets" />

<Target Name="GenerateNuGetConfig" >
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this file is added to Xamarin.Android-Tests.sln, could you please test the following?

  1. Within Visual Studio for Mac,
  2. Load Xamarin.Android-Tests.sln.
  3. Add a new project to the .sln.

What happens?

Normally, what would happen. is that every .csproj in the .sln is "re-formatted", screwing up whitespace, and requiring a git checkout -f HEAD … to clean things up.

I don't know if this is still the case for .NET 5+ projects/SDK short-form projects. This is the case for "normal" projects.

It would likely be safer to move these <Target/>s into Directory.Build.targets.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should add this to Xamarin.Android-Tests.sln at the moment, as it will break our macOS build job. These new project files will only compile against a specific version of .NET 5 that also has our workload installed into it. Additionally, I think there is still IDE work underway that will be needed to be able to load and use a project with a target framework of net5.0-android. I will move the targets over, but I don't think we should include any net5.0-android projects in our legacy solutions, or if we do want to do so eventually we should at least wait until there is a .NET 6 public preview available that supports it.

pjcollins added a commit to pjcollins/android that referenced this pull request Nov 9, 2020
Context: dotnet#5250

PR dotnet#5250 will be adding another another Mono.Android-Tests project file,
and it feels like a good time to move all relevant Mono.Android test
source into a single location and reduce duplication where possible.

The `src/Mono.Android/Test/` folder has been moved into the top level
`tests` directory.  The two existing `tests/Runtime-*` folders have been
moved under the new `tests/Mono.Android-Tests` folder.  Some duplication
that existed in the .targets and .projitems files that belonged to these
test projects has been cleaned up.

The obsolete `TestInstrumentation` class has been deleted in favor of
the newer `NUnitInstrumentation` class.

The `Build.GetSerial ()` API is restricted on API 29+, so a check has
been added to prevent the following exception:

    AndroidRuntime: FATAL EXCEPTION: Instr: xamarin.android.runtimetests.NUnitInstrumentation
    AndroidRuntime: Process: Mono.Android_Tests, PID: 3489
    AndroidRuntime: java.lang.SecurityException: getSerial: The user 10106 does not meet the requirements to access device identifiers.
    AndroidRuntime: 	at android.os.Parcel.createException(Parcel.java:2071)
    AndroidRuntime: 	at android.os.Parcel.readException(Parcel.java:2039)
    AndroidRuntime: 	at android.os.Parcel.readException(Parcel.java:1987)
    AndroidRuntime: 	at android.os.IDeviceIdentifiersPolicyService$Stub$Proxy.getSerialForPackage(IDeviceIdentifiersPolicyService.java:159)
    AndroidRuntime: 	at android.os.Build.getSerial(Build.java:162)
pjcollins added a commit to pjcollins/android that referenced this pull request Nov 9, 2020
Context: dotnet#5250

PR dotnet#5250 will be adding another another Mono.Android-Tests project file,
and it feels like a good time to move all relevant Mono.Android test
source into a single location and reduce duplication where possible.

The `src/Mono.Android/Test/` folder has been moved into the top level
`tests` directory.  The two existing `tests/Runtime-*` folders have been
moved under the new `tests/Mono.Android-Tests` folder.  Some duplication
that existed in the .targets and .projitems files that belonged to these
test projects has been cleaned up.

The obsolete `TestInstrumentation` class has been deleted in favor of
the newer `NUnitInstrumentation` class.

The `Build.GetSerial ()` API is restricted on API 29+, so a check has
been added to prevent the following exception:

    AndroidRuntime: FATAL EXCEPTION: Instr: xamarin.android.runtimetests.NUnitInstrumentation
    AndroidRuntime: Process: Mono.Android_Tests, PID: 3489
    AndroidRuntime: java.lang.SecurityException: getSerial: The user 10106 does not meet the requirements to access device identifiers.
    AndroidRuntime: 	at android.os.Parcel.createException(Parcel.java:2071)
    AndroidRuntime: 	at android.os.Parcel.readException(Parcel.java:2039)
    AndroidRuntime: 	at android.os.Parcel.readException(Parcel.java:1987)
    AndroidRuntime: 	at android.os.IDeviceIdentifiersPolicyService$Stub$Proxy.getSerialForPackage(IDeviceIdentifiersPolicyService.java:159)
    AndroidRuntime: 	at android.os.Build.getSerial(Build.java:162)
jonpryor pushed a commit that referenced this pull request Nov 11, 2020
Context: #5250

PR #5250 will be adding another another Mono.Android-Tests project
file, and it feels like a good time to move all relevant Mono.Android
test source into a single location and reduce duplication.

Move the `src/Mono.Android/Test/` folder to the
`tests/Mono.Android-Tests` directory.

The two existing `tests/Runtime-*` folders have been moved under the
new `tests/Mono.Android-Tests` folder.  Some duplication that existed
in the `.targets` and `.projitems` files that belonged to these test
projects has been cleaned up.

The obsolete `TestInstrumentation` class has been deleted in favor of
the newer `NUnitInstrumentation` class.

The `Build.GetSerial ()` API is restricted on API 29+, so a check has
been added to `TestInstrumentation.LogDeviceInfo()` to prevent the
following exception:

	AndroidRuntime: FATAL EXCEPTION: Instr: xamarin.android.runtimetests.NUnitInstrumentation
	AndroidRuntime: Process: Mono.Android_Tests, PID: 3489
	AndroidRuntime: java.lang.SecurityException: getSerial: The user 10106 does not meet the requirements to access device identifiers.
	AndroidRuntime: 	at android.os.Parcel.createException(Parcel.java:2071)
	AndroidRuntime: 	at android.os.Parcel.readException(Parcel.java:2039)
	AndroidRuntime: 	at android.os.Parcel.readException(Parcel.java:1987)
	AndroidRuntime: 	at android.os.IDeviceIdentifiersPolicyService$Stub$Proxy.getSerialForPackage(IDeviceIdentifiersPolicyService.java:159)
	AndroidRuntime: 	at android.os.Build.getSerial(Build.java:162)
@pjcollins pjcollins force-pushed the net5-runtime-tests branch 3 times, most recently from 0a57943 to d8bde8a Compare November 12, 2020 15:34
A new version of Mono.Android-Tests has been added to run against the
.NET 6 SDK:

 * `tests/Mono.Android-Tests/Runtime-Microsoft.Android.Sdk/Mono.Android.NET-Tests.csproj`

To support this, new .NET .csproj files have been added alongside all of
the existing legacy Xamarin.Android unit test library projects.  These
projects target `net5.0-android` and build against our .NET 6 SDK:

 * `src/Mono.Android/Test/Java.Interop-Tests/Java.Interop-Tests.NET.csproj`
 * `src/Mono.Android/Test/Mono.Android-Test.Library/Mono.Android-Test.Library.NET.csproj`
 * `src/Xamarin.Android.NUnitLite/Xamarin.Android.NUnitLite.NET.csproj`
 * `tests/TestRunner.Core/TestRunner.Core.NET.csproj`
 * `tests/TestRunner.NUnit/TestRunner.NUnit.NET.csproj`

The `_CreateAar` target was being skipped for the new Java.Interop-Tests.NET
project, as it had no inputs.  As a result, the `Mono.Android-Test-classes.jar`
file required by these tests was not being included in the application project.
To fix this, I've added `@(AndroidJavaLibrary)` to `@(_CreateAarInputs)` so that
these items will also be considered as inputs for this target/task.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants