在 VS2015 上使用 NUnit 对 UWP 应用进行单元测试 [英] Unit test UWP app with NUnit on VS2015

查看:54
本文介绍了在 VS2015 上使用 NUnit 对 UWP 应用进行单元测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我花了太多时间尝试在 Microsoft Store 应用上运行基本的 NUnit 测试.我在 VS2015 Pro 上安装了 NUnit v3.0.1 和 NUnit3TestAdapter,但我得到以下确认未发现测试:

I spent far too much time trying to run a basic NUnit test on a Microsoft Store app. I installed NUnit v3.0.1 and NUnit3TestAdapter on VS2015 Pro but I get the following which confirms that the test is not discovered:

------ 发现测试开始------NUnit Adapter 3.0.8.0 发现测试已启动异常 NUnit.Engine.NUnitEngineException,在 <project exe file> 中发现测试时抛出异常NUnit 3.0 驱动程序不支持 NUnit 的便携版本.使用特定于平台的跑步者.NUnit Adapter 3.0.8.0 发现测试完成========== 发现测试完成:0 发现 (0:00:01.0639991) ==========

引用的 NUnit.Engine.NUnitEngineException 错误没有帮助,因为无法探索异常在我的程序中的位置.测试是一个带有一个 Assert 语句的单一方法,只是为了测试设置是否有效,所以没有什么复杂的.我也不明白什么是特定于平台的跑步者".我通过 NuGet 包管理器安装了 NUnit 和 NUnit3TestAdapter,并且我认为已执行相关平台和版本的安装.

The NUnit.Engine.NUnitEngineException error referred to is not helpful because there is no way of exploring where the exception is in my program. The test is a single method with one Assert statement just to test if the setup works so there is nothing complicated. 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.

我什至尝试安装NUnit Templates for Visual Studio".这允许我创建一个 NUnit 项目,有趣的是 NUnit 项目中的测试被发现并运行.但缺点是我无法从正在运行的 NUnit 项目中引用我的 UWP 应用项目,我认为是因为 NUnit 项目仅支持 .Net 框架(最高 4.6.1)而不是 Windows 10 平台.

I even tried out installing "NUnit Templates for Visual Studio". This allowed me to create an NUnit project, and interestingly the test within NUnit project is discovered and run. 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.

我以前在非 UWP 应用程序中使用过 NUnit,没有太多麻烦.是我遗漏了什么还是 NUnit 还不支持 UWP 应用?

I have used NUnit before for non UWP applications without much trouble. Am I missing something or NUnit as yet doesn't support UWP apps?

推荐答案

目前您只能使用 XUnit 测试 DNX 项目.
这里是一个很好的起点.

At the moment you can only test DNX projects with XUnit.
Here is a nice starting point for that.

来自官方的 Asp.Net 5 文档(使用与 UWP 相同的基础结构):

From the official Asp.Net 5 documentation (which uses the same infrastructure as UWP):

例如,要使用 xUnit 测试框架,您需要配置依赖项如下:[示例 project.json 我不想复制]
随着其他测试框架发布对 DNX 的支持,我们将在此处链接到它们.

For example, to work with the xUnit test framework, you would configure the dependencies as follows: [example project.json I dont want to copy]
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.

这篇关于在 VS2015 上使用 NUnit 对 UWP 应用进行单元测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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