简体   繁体   中英

Unit Testing a Windows Phone 7.1 library

I'm extremely new to Windows Phone development and I've read, for example here , that there is no unit testing framework for Windows Phone applications.

This I found it weird since, for example if I have a class library with a bunch of classes that execute operations I would create a unit testing project, add a reference of the class library and unit test each class the same way I've always had.

So I created a dummy Windows Phone class library with a MyClass class with an Add(int x, int y) method on it, and added its reference to a regular test project.

The interesting thing is that the reference has a warning sign on it, but the tests run, pass and fail accordingly.

So my questions are:

What is the real deal with unit testing Windows Phone code?
Why is there a warning sign by the reference of the Windows Phone class library in the test project?

Thanks for your enlightment :)

I have been doing some test driven development on WP7. I am using NUnit and Moq for Silverlight for my isolation framework. There is a great blog article on using NUnit and Moq on Windows Phone 7 with a video on dealing with some oddities, http://toranbillups.com/blog/archive/2011/07/24/Test-Driving-My-Windows-Phone-7-App . Most of what I have seen so far is more integration tests, and do work great for most WP7 applications.

Happy Coding!!

You can definitely unit test Windows Phone 7 code. I believe that these days NUnit supports it, and even back when it was pretty new, there was the Silverlight Unit Test Framework . You may well find that some other techniques you usually use are either limited or don't exist (for example, when I was writing a WP7 app, I don't think any mocking libraries worked with it) and it's generally a bit more painful than unit testing with the full framework, but it's definitely feasible.

Oh, and you may well find yourself wanting to hide some of the abstractions of the rest of the framework, such as WebRequest , so that you can test things which want to use those abstractions. I found this painful, but workable...

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