简体   繁体   English

在VS2015上使用xUnit测试UWP应用程序

[英]Testing UWP app with xUnit on VS2015

I have managed to create an xUnit project on VS2015 to unit-test UWP apps. 我已经设法在VS2015上创建一个xUnit项目来对UWP应用进行单元测试。 There is a background to this question here on stackoverflow which gives some context to this question. 这里有关于stackoverflow这个问题的背景知识,它给出了这个问题的一些背景。

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. 我理解引用的项目(将进行单元测试)导致a user callback threw an exception但我没有看到调试此错误的明显方法。 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? 有没有人知道如何深入了解导致a user callback threw an exception原因是什么导致a user callback threw an exception错误? 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. 好的,做了一些研究和自学,现在我可以回答我自己的问题了。

The most important fact: 最重要的事实:

You cannot unit test a UWP project, only a class library (at this time). 您不能单元测试UWP项目,只能测试类库(此时)。

The above is a quote from Jerry Nixon (see toward the end of linked page). 以上是Jerry Nixon的引用 (见链接页面末尾)。 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. 所以,这说明了一切,但不知道这个重要的事实无疑会让你对我进行疯狂的追逐。

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.); 上述意味着,如果您还没有完成,则需要将应用项目拆分为UI部分(视图和其他UI相关部分),其余部分拆分为非UI库项目(包括模型,数据访问)方法等); the non-UI library project being the candidate to be unit-tested. 非UI库项目是单元测试的候选项目。 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. 对未来也有启发意义。

The above error is therefore due to referencing a UI laden UWP project which cannot be tested at this time. 因此,上述错误是由于引用了一个无法在此时测试的UI负载UWP项目。

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

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