1
votes

I am creating a Xamarin.UITest for my android project. I am following the Microsoft guide. Everything works fine right up untill the last point:

Add a project reference from the UITest project to the Xamarin.Android project:

enter image description here

This will allow the NUnitTestAdapter to run the UITests for the Android app from Visual Studio.

As soon as I add a reference to an Android project it gives these errors:

NU1201: Project uitest.Android is not compatible with net461 (.NETFramework,Version=v4.6.1). Project uitest.Android supports: monoandroid81 (MonoAndroid,Version=v8.1)

Which makes perfect sense because obviously a .Net Framework 4.6.1 library knows nothing about MonoAndroid.

I have also tried converting it to .Net Standard 2.0 but I get a similar error:

Error NU1201 Project uitest.Android is not compatible with netstandard2.0 (.NETStandard,Version=v2.0). Project uitest.Android supports: monoandroid81 (MonoAndroid,Version=v8.1)

Strangely the project still builds despite the errors. BUT these errors fail my automated build nuget restore with exactly the same error.

The reason the UI Test references the Android project is for the Xamarin Test Cloud to be able to call:

    if (platform == Platform.Android)
    {
        return ConfigureApp.Android.StartApp();
    }

    return ConfigureApp.iOS.StartApp();

You can't use InstalledApp or ApkFile methods in Xamarin test cloud

Have I misunderstood something or is this a visual studio / Xamarin bug?

PS. I am using latest Visual Studio version VS 15.8.0

1

1 Answers

1
votes

You typically won't reference your Android project in your UI-test project. The reason for this is that:

  • You might test an app you only have the apk or ipa for
  • Cloud solutions like Test Cloud won't have access to the source code and therefor won't compile the code.

I am using the apk like this:

[TestFixture]
public class DroidTest
{
    const string _droidPath = "../../APK/my-app.apk";
    IApp _app;

    [TestFixtureSetUp]
    public void Setup()
    {
        _app = ConfigureApp.Android.ApkFile(_droidPath).StartApp();
    }
}

If you made changes in the Android project build and create a new apk. After that re-run your tests.