locked
[UWP][C++] Platform::ClassNotRegisteredException - In-process references to applications are not supported in tests. RRS feed

  • Question

  • Hello,
    I'm relatively new to unit testing and I'm having a rather difficult time getting a Universal Windows Unit Test Project up and running with an existing Universal Windows Project code-base. 

    So far I have :

    • created a Univeral Windows Unit Test Project and added it to my solution,
    • added a reference to the UWP project in the unit test project,
    • updated the linker's include & using directories to point at my UWP project's source files.

    For now, I'm trying to test a static singleton that verifies user inputs, and some of my tests look a little like this.

    TEST_METHOD(Signup_CreateSignupVerifier)
    {
    	// check that the GetInstance function returns something
    	auto sv = SignupVerifier::GetInstance();
    	Assert::IsNotNull(sv);
    }
    
    TEST_METHOD(Signup_Username_TooShort)
    {
    	// check that the username fails if it is less than 5 characters
    	Assert::IsTrue(SignupVerifier::GetInstance()->usernameIncorrectLength("foo"));
    }

    But both of these tests fail with the error 
    Message: Unhandled WinRT Exception : Platform::ClassNotRegisteredException
    Please check if test is taking reference from an Application. In-process references to applications are not supported in tests.

    I'm having a hard time Googling this problem. Am I just going about this the wrong way? If anyone has any suggestions on how to get a test like this working, or has any references that they can recommend to help get me up and running I would greatly appreciate it.

    Thanks,
    ~Kyler


    • Edited by Kyler Mulherin Monday, October 17, 2016 11:04 PM changed the wording a little.
    Monday, October 17, 2016 11:02 PM

All replies

  • Hi Kyler,

    Thanks for your post.

    >>Message: Unhandled WinRT Exception : Platform::ClassNotRegisteredException
    Please check if test is taking reference from an Application. In-process references to applications are not supported in tests.

    According to the error message, it seems that the reference is not supported in test class.  Please follow the steps in this document below and test it again and check the result.

    https://msdn.microsoft.com/en-us/library/hh440545.aspx?f=255&MSPPError=-2147217396

    Best Regards,

    Lake Xiao

    Wednesday, October 19, 2016 1:58 AM
  • Hello Lake, thank you for your suggestion.

    Unfortunately, the article you linked is for utilizing a Unit Test Library for Windows 8.1 apps. When I try to reference my Windows 10 UWP project, I get the message
    "A reference to 'MyProject' cannot be added because the two projects target two different platforms."

    I have tried to use similar steps with a Windows 10 Universal Unit Test App, but I'm still stuck with my original problem.

    What is the expected way to Unit Test code in another project?


    • Edited by Kyler Mulherin Wednesday, October 19, 2016 8:26 PM wording and grammar.
    Wednesday, October 19, 2016 8:15 PM
  • Hi Kyler Mulherin,

    How about testing using C# project template?

    I did a test in my side and followed your steps, It can work well when using C# windows 10 unite test app.

    Best Regards,

    Lake Xiao


    • Edited by lake Xiao Thursday, October 20, 2016 1:51 AM
    Thursday, October 20, 2016 1:51 AM
  • Hello Lake,

    Could you elaborate a little about which project template you mean? I'm not seeing anything in the menu with that name.

    In Solution >> Add >> New Project >> Visual C# >> Windows, the unit test options I see are :

    • Unit Test Library (Windows)
    • Unit Test App (Universal Windows)
    • Coded UI Test Project (Universal Windows - Phone)
    • Coded UI Test Project (Universal Windows)

    Are you referring to an xUnit Test Project Template?

    Also, I'm working with a c++ project,  will c# unit test projects work with c++ code?

    Thursday, October 20, 2016 10:02 PM
  • Hi Kyler,

    I am trying to involve someone familiar with this topic to further look at this issue. There might be some time delay. Appreciate your patience.

    Best Regards,

    Lake Xiao

    Monday, October 24, 2016 1:37 AM