简体   繁体   中英

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

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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