简体   繁体   English

在VS2015上使用NUnit进行单元测试UWP应用

[英]Unit test UWP app with NUnit on VS2015

I spent far too much time trying to run a basic NUnit test on a Microsoft Store app. 我花了太多时间试图在Microsoft Store应用程序上运行基本的NUnit测试。 I installed NUnit v3.0.1 and NUnit3TestAdapter on VS2015 Pro but I get the following which confirms that the test is not discovered: 我在VS2015 Pro上安装了NUnit v3.0.1和NUnit3TestAdapter,但得到以下确认未发现测试的信息:

------ Discover test started ------ NUnit Adapter 3.0.8.0 discovering tests is started Exception NUnit.Engine.NUnitEngineException, Exception thrown discovering tests in <project exe file> The NUnit 3.0 driver does not support the portable version of NUnit. Use a platform specific runner. NUnit Adapter 3.0.8.0 discovering test is finished ========== Discover test finished: 0 found (0:00:01.0639991) ==========

The NUnit.Engine.NUnitEngineException error referred to is not helpful because there is no way of exploring where the exception is in my program. 提到的NUnit.Engine.NUnitEngineException错误没有帮助,因为无法探索异常在程序中的位置。 The test is a single method with one Assert statement just to test if the setup works so there is nothing complicated. 该测试是带有一个Assert语句的单一方法,仅用于测试设置是否有效,因此没有什么复杂的问题。 I also don't understand what a "platform specific runner" is. 我也不明白什么是“特定于平台的跑步者”。 I installed both NUnit and NUnit3TestAdapter thru NuGet Package Manager and I presume installations for relevant platform and version are carried out. 我通过NuGet软件包管理器安装了NUnit和NUnit3TestAdapter,并且我假设执行了相关平台和版本的安装。

I even tried out installing "NUnit Templates for Visual Studio". 我什至尝试安装“ Visual Studio NUnit模板”。 This allowed me to create an NUnit project, and interestingly the test within NUnit project is discovered and run. 这使我可以创建一个NUnit项目,有趣的是,发现并运行了NUnit项目中的测试。 But the downside is that I cannot reference my UWP app project from the working NUnit project, I think because the NUnit project only supports .Net frameworks (up to 4.6.1) not Windows 10 platforms. 但是缺点是我无法从正在运行的NUnit项目中引用我的UWP app项目,因为NUnit项目仅支持.Net框架(最高4.6.1),而不支持Windows 10平台。

I have used NUnit before for non UWP applications without much trouble. 之前,我已经将NUnit用于非UWP应用程序而没有太多麻烦。 Am I missing something or NUnit as yet doesn't support UWP apps? 我是否缺少某些东西或NUnit尚不支持UWP应用程序?

At the moment you can only test DNX projects with XUnit. 目前,您只能使用XUnit测试DNX项目。
Here is a nice starting point for that. 是一个不错的起点。

From the official Asp.Net 5 documentation (which uses the same infrastructure as UWP): 来自官方的Asp.Net 5 文档 (使用与UWP相同的基础结构):

For example, to work with the xUnit test framework, you would configure the dependencies as follows: [example project.json I dont want to copy] 例如,要使用xUnit测试框架,您可以按以下方式配置依赖项:[我不想复制的示例project.json]
As other test frameworks release support for DNX, we will link to them here. 随着其他测试框架发布对DNX的支持,我们将在此处链接到它们。

Since there are no other frameworks linked in the documentation, I assume that there are none that support DNX projects at the moment. 由于文档中没有链接其他框架,因此我假设目前没有支持DNX项目的框架。

Since this question was originally posted NUnit has developed it's support for testing UWP/Xamarin apps. 自从这个问题最初发布以来,NUnit就已经开发了它对测试UWP / Xamarin应用程序的支持。 Check out the nunit.xamarin runners. 查看nunit.xamarin运行程序

Essentially, your tests should be created in either a portable library, or a shared project. 本质上,您的测试应该在可移植库或共享项目中创建。 This can then be referenced by a UWP project runner, which can be run on the emulator. 然后,可以由UWP项目运行程序引用此文件,该项目运行程序可以在模拟器上运行。

If you take the shared project approach, you can also reference this through an .NET 4.5 project, which will allow your tests to integrate with the NUnit VS adapter, and show up in VS. 如果采用共享项目方法,则还可以通过.NET 4.5项目引用此方法,这将使您的测试与NUnit VS适配器集成,并显示在VS中。 Portable libraries can not yet be run with this runner, however that's in the pipeline. 便携式库不能与这个亚军运行,但是这是在管道。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM