【发布时间】:2023-03-06 20:56:01
【问题描述】:
在我的 Locationer 类中,我有函数 GetLocationAsync(),它使用 Xamarin.Essentials: Geolocation。这个函数工作正常,但我想为这个函数创建单元测试。
我创建了 xUnitTests 项目和单元测试:
public async Task LocationTest()
{
Locationer locationer = new Locationer();
var actual = locationer.GetLocationAsync();
Assert.Equal("test", actual);
}
在 Xamarin Forms 项目中 GetLocationAsync() 返回“纬度:46.55465,经度:15.64588,高度:262”。
在我的单元测试中GetLocationAsync() 返回“此功能未在此程序集的可移植版本中实现”
是否可以在我的单元测试项目中使用 Xamarin.Essentials:地理位置?我该如何解决?
【问题讨论】:
-
我建议将实现问题抽象出来。
标签: c# unit-testing xamarin xunit xamarin.essentials