在 VS2015 上使用 xUnit 测试 UWP 应用 [英] Testing UWP app with xUnit on VS2015

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

问题描述

我设法在 VS2015 上创建了一个 xUnit 项目来对 UWP 应用程序进行单元测试.这个问题有一个背景这里在stackoverflow 给出了这个问题的一些背景.

I have managed to create an xUnit project on VS2015 to unit-test UWP apps. There is a background to this question here on stackoverflow which gives some context to this question.

我可以编译并运行测试,但是当我引用要测试的项目时,出现以下错误.

I can compile and run the test, however when I reference a project to be tested, the following error comes up.

------ Run test started ------
Updating the layout...

Checking whether required frameworks are installed...

Registering the application to run from layout...

Deployment complete (1857ms). Full package name: "8f4533e5-fec8-415b-94ab-6bce6b37374f_1.0.0.0_x86__5gyrq6psz227t"

A user callback threw an exception.  Check the exception stack and inner exception to determine the callback that failed.
========== Run test finished: 0 run (0:00:04.3378913) ==========

我了解引用的项目(将进行单元测试)导致 用户回调引发异常,但我看不到调试此错误的明显方法.执行模式看起来不像可以用断点检查的正常调试.

I understand the referenced project (which is to be unit-tested) is causing the a user callback threw an exception but I see no obvious way to debug this error. The mode of execution doesn't look like a normal debug that can be examined with breakpoints.

有谁知道如何挖掘并找出导致用户回调引发异常错误的原因?要测试的应用项目没有错误并且可以自行正常运行.

Does anybody know how to dig into and find out what is causing the a user callback threw an exception error? The app project to be tested is error-free and runs fine on its own.

推荐答案

好的,做了一些研究和自学,现在我可以回答我自己的问题了.

Okay, did some researching and self-learning and now I can answer my own question.

最重要的事实:

您不能对 UWP 项目进行单元测试,只能对类库进行单元测试(此时).

You cannot unit test a UWP project, only a class library (at this time).

以上是 Jerry Nixon 的引用(见链接页面末尾).所以,这就是全部,但不知道这个重要的事实无疑会让你像对我一样疯狂追逐.

The above is a quote from Jerry Nixon (see toward the end of linked page). So, that says it all, but not knowing this important fact will no doubt set you on a wild goose chase as it did to me.

上面的意思是,如果你还没有做,你需要把你的app项目拆分成UI部分(View和其他UI相关的部分),剩下的分成非UI库项目(包括models)、数据访问方法等);非 UI 库项目是要进行单元测试的候选项目.幸运的是,使用我的应用程序很容易实现这一点,现在我可以通过引用测试项目中的类库部分来对应用程序中最关键的部分进行单元测试.对未来也很有启发.

What the above means is that, if you haven't done already, you need to split your app project into the UI part (View and other UI related parts), and the rest into non-UI library project (comprising models, data access methods, etc.); the non-UI library project being the candidate to be unit-tested. Fortunately, it was easy to accomplish this with my app and now I can unit test the most crucial parts of my app by referencing the class library part in the test project. Is was also instructive for the future.

因此,上述错误是由于引用了当前无法测试的 UI 负载 UWP 项目.

The above error is therefore due to referencing a UI laden UWP project which cannot be tested at this time.

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

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