Xamarin.mac单元测试项目 [英] Xamarin.mac unit test project
问题描述
我正在尝试为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:
- 将程序集与guiunit打包在一起并运行它们的传统方式: https://developer.xamarin.com/samples/mac/guiunit-example/
- 创建XM应用程序并直接包含guiunit的不太标准的方法:传统方法更易于集成到现有的nunit工作流程中,而更新的非标准方法则更易于调试.
The traditional way is easier to integrate into existing nunit workflows, while the newer less standard way is easier to debug.
这篇关于Xamarin.mac单元测试项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!