I am trying to run basic test by Xamarin.UITest:
using NUnit.Framework;
using System;
using Xamarin.UITest;
namespace ProjectUITest
{
[TestFixture]
public class Tests
{
IApp _app;
[SetUp]
public virtual void BeforeEachTest()
{
_app = ConfigureApp
.Android
.ApkFile("C:/xxx/bin/Debug/net8.0-android/xxx.apk")
.StartApp();
}
[Test]
public void Test1()
{
}
}
}
And there is an issue:
Test1
Source: UnitTest1.cs line 22
Duration: 11,2 sec
Message:
System.Net.Http.HttpRequestException : An error occurred while sending the request.
----> System.Net.Http.HttpIOException : The response ended prematurely. (ResponseEnded)
Stack Trace:
HttpClient.SendData(String endpoint, String method, HttpContent content, ExceptionPolicy exceptionPolicy, Nullable`1 timeOut)
HttpClient.Post(String endpoint, String arguments, ExceptionPolicy exceptionPolicy, Nullable`1 timeOut)
HttpApplicationStarter.Execute(String intentJson)
AndroidAppLifeCycle.LaunchApp(String appPackageName, ApkFile testServerApkFile, Int32 testServerPort)
AndroidAppLifeCycle.LaunchApp(ApkFile appApkFile, ApkFile testServerApkFile, Int32 testServerPort)
AndroidApp.ctor(IAndroidAppConfiguration appConfiguration, IExecutor executor)
AndroidApp.ctor(IAndroidAppConfiguration appConfiguration)
AndroidAppConfigurator.StartApp(AppDataMode appDataMode)
Tests.BeforeEachTest() line 15
RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr)
--HttpIOException
HttpConnection.SendAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
The Android Emulator is trying to run this test, the screen changes but after short time the issue appears. I suppose there is some problem with Android Emulator. Also I unchecked “Fast deploment” in the tested project properties.
Test project settings:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="coverlet.collector" Version="6.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="NUnit" Version="3.14.0" />
<PackageReference Include="NUnit.Analyzers" Version="3.9.0" />
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0" />
<PackageReference Include="SharpZipLib" Version="1.4.2" />
<PackageReference Include="Xamarin.UITest" Version="4.3.4" />
</ItemGroup>
<ItemGroup>
<Using Include="NUnit.Framework" />
</ItemGroup>
</Project>