【发布时间】:2021-02-01 23:22:08
【问题描述】:
我正在为我的 Xamarin.Forms 应用程序运行单元测试,单元测试抛出 Xamarin.Essentials.NotImplementedInReferenceAssemblyException:
我为应用创建了一个单元测试项目(使用 NUnit 3.12.0)并编写了以下代码来测试功能。
[TestFixture()]
public class Test
{
[Test()]
public void TestCase()
{
AutoResetEvent autoEvent = new AutoResetEvent(true);
SomeClass someClass = new SomeClass();
someClass.SomeFunction((response) =>
{
Assert.AreEqual(response, "Hello")
autoEvent.Set();
});
autoEvent.WaitOne(); //** Xamarin.Essentials.NotImplementedInReferenceAssemblyException thrown here**
}
}
以下是来自 Xamarin.Forms 应用的正在测试代码:
public class SomeClass
{
public void SomeFunction(Action<string> callback)
{
// asynchronous code...
callback("Hello");
}
}
上述功能在 Xamarin.Forms 应用中运行良好。
注意:我读到可以使用 await/async,但是,我将不得不在整个项目中进行更改。目前这不是一个可行的解决方案。
编辑 1: 我创建了一个示例 Xamarin.Forms 项目,其中包含单元测试。项目可用here
【问题讨论】:
-
请看github.com/xamarin/Essentials/issues/520,由于多种原因,使用 Xamarin.Essentials 进行单元测试可能需要在接口方面付出更多努力,并且有使用 Xamarin.Essentials 进行单元测试的建议。跨度>
标签: c# unit-testing xamarin.forms nunit xamarin.essentials