Unit test UWP app with NUnit on VS2015

混江龙づ霸主 提交于 2019-12-24 15:36:53

问题


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:

------ 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. 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.

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.

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?


回答1:


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

From the official Asp.Net 5 documentation (which uses the same infrastructure as 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]
As other test frameworks release support for DNX, we will link to them here.

Since there are no other frameworks linked in the documentation, I assume that there are none that support DNX projects at the moment.




回答2:


Since this question was originally posted NUnit has developed it's support for testing UWP/Xamarin apps. Check out the nunit.xamarin runners.

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.

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. Portable libraries can not yet be run with this runner, however that's in the pipeline.



来源:https://stackoverflow.com/questions/34652494/unit-test-uwp-app-with-nunit-on-vs2015

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!