locked
What is the best way to unit test UWP library work? RRS feed

  • Question

  • Dear all,

    If I'm developing a code library to be used for UWP app, what is the best way to do Unit testing for it?

    Currently I know that one can create a new "Unit Test App (UWP)", then nuget xunit in and remove ref to MSTest, but is that it? The problem with it:

    1, even for a single test run the runner will spin up an empty APP

    2, therefore it's slow, very S - L - O - W

    3, it can't be headless, think about CI/CD testing env

    4, what about other testing framework, nunit?

    Best regards,

    Dong

    • Moved by Barry Wang Friday, February 19, 2016 7:56 AM
    Monday, February 15, 2016 5:08 PM

Answers

  • Hi Xied75,

    It seems that other members also got this kind of issue before:

    https://social.msdn.microsoft.com/Forums/vstudio/en-US/f39e3d06-0742-4bfb-9d92-70e6bf500bed/unit-testing-for-portable-class-library?forum=vsunittest

    Maybe PCL Testing is a simple good test framework for writing portable tests.

    Reference:

    https://github.com/dsplaisted/pcltesting

    Note: This response contains a reference to a third party World Wide Web site. Microsoft is providing this information as a convenience to you.

    Microsoft does not control these sites and has not tested any software or information found on these sites;

    Therefore, Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there.

    There are inherent dangers in the use of any software found on the Internet, and Microsoft cautions you to make sure that you completely understand the risk before retrieving any software from the Internet.

    Thanks,

    Jack


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, February 25, 2016 6:53 AM

All replies

  • Is the code library a PCL?

    http://pauliom.wordpress.com

    Monday, February 15, 2016 5:31 PM
  • The code library is a new "Class Library (UWP)" I'm creating.
    Monday, February 15, 2016 5:33 PM
  • Make as much of it as PCL a possible, then you won't have to invoke any device fake or otherwise.

    http://pauliom.wordpress.com


    • Edited by pkr2000 Monday, February 15, 2016 7:32 PM
    Monday, February 15, 2016 7:32 PM
  • you can try to create UWP library in Shared Project, so UWP and desktop unit test project both can reference to the same shared project
    Monday, February 15, 2016 8:23 PM
  • YuGUAN I don't think that helps? The point is to use a unit test framework that doesn't require the overhead of invoke any form of device to test. Unless you have something in mind that can work with a UWP library and not incur that cost?

    http://pauliom.wordpress.com

    Monday, February 15, 2016 9:09 PM
  • Correct me if I'm wrong, but PCL is on the way out? Also how does one create a PCL project in VS 2015 targeting Windows 10 UWP? I thought even a library marked as PCL doesn't guarantee it will work with UWP as there are limitations on .NET api available in that sandbox.  

    Tuesday, February 16, 2016 10:42 AM
  • I don't know where that has come from. Not saying you're wrong but I'm using PCLs for win10. I can't see why they don't have a future. Libraries aren't and shouldn't be restricted to win10.

    http://pauliom.wordpress.com

    Tuesday, February 16, 2016 11:44 AM
  • PCL for Win 10 UWP or desktop?

    According to this we don't really have full .NET to access in UWP: https://msdn.microsoft.com/en-us/library/windows/apps/mt185501.aspx

    How do I create a PCL library with VS 2015 that can target UWP?

    Thanks for the helps!

    Tuesday, February 16, 2016 11:50 AM
  • I created a new library and selected 'Windows Universal 10'

    http://pauliom.wordpress.com

    Tuesday, February 16, 2016 1:50 PM
  • Hi, Would you mind to expand on this a bit? I'm using VS 2015 community version, what is the exact click sequence to allow me to create a PCL project that I can target UWP?

    Best,

    Dong

    Tuesday, February 16, 2016 4:52 PM
  • New Project -> Class Library (Portable) -> Windows Universal 10

    http://pauliom.wordpress.com

    Tuesday, February 16, 2016 9:42 PM
  • Hello Dong,

    It seems you are talking about unit test in your first post. I just want to share this, if the question is about Unit Test for your PCL library, you can consider this forum: https://social.msdn.microsoft.com/Forums/vstudio/en-US/home?forum=vsunittest The unit test for UWP apps and libraries are all supported there.

    Best regards,

    Barry


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    • Edited by Barry Wang Wednesday, February 17, 2016 8:33 AM
    Wednesday, February 17, 2016 8:32 AM
  • No, the question isn't about unit testing a PCL, it about how best to unit test a library. We were discussing advantages of using a PCL to help speed up testing.

    http://pauliom.wordpress.com

    Wednesday, February 17, 2016 9:37 AM
  • Just to confirm with a detailed click sequence: New Project -> Installed -> Templates -> Visual C# -> Windows -> Classic Desktop -> Class Library (Portable). Then yes we can choose Windows Universal 10.0 as a target.

    Thanks for the help. Before I just stopped at "Classic Desktop" as I thought that won't work for UWP.

    But the testing question is still open.

    Wednesday, February 17, 2016 4:01 PM
  • Once you have a PCL you can use pretty much any testing framework and it won't incur any heavy 'device' overhead.

    http://pauliom.wordpress.com


    • Edited by pkr2000 Wednesday, February 17, 2016 4:25 PM
    Wednesday, February 17, 2016 4:10 PM
  • No it doesn't work. The library is now PCL, but if it's targeting UWP then you can't add that into a Testing project which is not itself a Portable. If you do that then Test Explorer won't show you anything because all major test runners can't do UWP yet.
    Wednesday, February 17, 2016 4:15 PM
  • You target .net too

    http://pauliom.wordpress.com

    Wednesday, February 17, 2016 7:15 PM
  • @pkr2000,

    Thanks, I understand it better. As the issue is more related to test I think I have to move it to the right forum.

    Best regards,

    Barry


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Friday, February 19, 2016 7:55 AM
  • Hi Xied75,

    It seems that other members also got this kind of issue before:

    https://social.msdn.microsoft.com/Forums/vstudio/en-US/f39e3d06-0742-4bfb-9d92-70e6bf500bed/unit-testing-for-portable-class-library?forum=vsunittest

    Maybe PCL Testing is a simple good test framework for writing portable tests.

    Reference:

    https://github.com/dsplaisted/pcltesting

    Note: This response contains a reference to a third party World Wide Web site. Microsoft is providing this information as a convenience to you.

    Microsoft does not control these sites and has not tested any software or information found on these sites;

    Therefore, Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there.

    There are inherent dangers in the use of any software found on the Internet, and Microsoft cautions you to make sure that you completely understand the risk before retrieving any software from the Internet.

    Thanks,

    Jack


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, February 25, 2016 6:53 AM