Xamarin.mac单元测试项目 [英] Xamarin.mac unit test project

查看:49
本文介绍了Xamarin.mac单元测试项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为Xamarin Mac类库项目创建一个单元测试项目.

I am trying to create a unit test project for a Xamarin Mac Class Library project.

.NET NUnit库项目无法正常工作,因为我无法添加对Xamarin Mac类库的引用,因此我尝试创建一个新的Xamarin Mac类库项目并向其添加了NUnit Nuget包.

.NET NUnit Library Project it doesn't work because I can't add a reference to my Xamarin Mac Class Library so I tried creating a new Xamarin Mac Class Library project and added NUnit Nuget package to it.

<package id="NUnit" version="3.5.0" targetFramework="xamarinmac20" />

它之所以起作用,是因为测试在测试管理器"中可见,但是不幸的是,每次我尝试运行单元测试时,都会收到加载失败"的消息.

For the first part it worked because the tests are visible in Test Manager but unfortunately every time I try to run the unit tests I receive "Load failed".

发生一个或多个错误.

Stack trace:
  at System.Threading.Tasks.Task.ThrowIfExceptional (System.Boolean includeTaskCanceledExceptions) [0x00014] in /private/tmp/source-mono-4.6.0-c8sr0/bockbuild-mono-4.6.0-branch-c8sr0/profiles/mono-mac-xamarin/build-root/mono-x86/mcs/class/referencesource/mscorlib/system/threading/Tasks/Task.cs:2157 
  at System.Threading.Tasks.Task`1[TResult].GetResultCore (System.Boolean waitCompletionNotification) [0x00034] in /private/tmp/source-mono-4.6.0-c8sr0/bockbuild-mono-4.6.0-branch-c8sr0/profiles/mono-mac-xamarin/build-root/mono-x86/mcs/class/referencesource/mscorlib/system/threading/Tasks/Future.cs:562 
  at System.Threading.Tasks.Task`1[TResult].get_Result () [0x00000] in /private/tmp/source-mono-4.6.0-c8sr0/bockbuild-mono-4.6.0-branch-c8sr0/profiles/mono-mac-xamarin/build-root/mono-x86/mcs/class/referencesource/mscorlib/system/threading/Tasks/Future.cs:532 
  at MonoDevelop.UnitTesting.NUnit.NUnitAssemblyTestSuite.RunUnitTest (MonoDevelop.UnitTesting.UnitTest test, System.String suiteName, System.String pathName, System.String testName, MonoDevelop.UnitTesting.TestContext testContext) [0x0014a] in /Users/builder/data/lanes/3816/fa52f026/source/monodevelop/main/src/addins/MonoDevelop.UnitTesting.NUnit/MonoDevelop.UnitTesting.NUnit/NUnitAssemblyTestSuite.cs:424 

推荐答案

Xamarin.Mac需要相当大的帮助才能将本机支持库放置在正确的位置/加载所有内容,然后确保只调用一次NSApplication.Init.,无论测试数量如何,等等.

Xamarin.Mac requires significant hand holding to place native support libraries in the right place / load everything up, and then assurance that you call NSApplication.Init only one time, no matter the number of tests, and so on.

让nunit做到这一点并非易事.我建议尝试 https://github.com/mono/guiunit .

Getting nunit to do that is non-trivial. I suggest trying https://github.com/mono/guiunit.

有两种使用guiunit的方法:

There are two ways to use guiunit:

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆