Using VS11 RC. I have a client executable written in C++ that I am trying to test with a C# Unit Test Library (Metro Style apps) project. The test fails with exception Class not registered HRESULT 0x80040154 (REGDB_E_CLASSNOTRG); I believe this is related to a warning in the test project: The executable ‘Client.exe’ is specified as the implementation for winmd file ‘C:.Client.winmd’. Only in-process servers are supported for generation of registration information in the app manifest. You will need to specify the out-of-process server registration information in the app manifest.
It appears to me that MSTest is looking for the class as a COM object, and that the warning is telling me that I need to specify it as an out-of-process server. Unfortunately, I don’t think I want to do that as it is an executable, and even if that is what I want, I can’t figure out how to do it.
I could simply move the class under test into a different project, but I don’t want to do that without a reason better than “I can’t get this to work”.
Is there any way to unit test a class defined in a Metro executable?
The code to be tested needs to be moved into a DLL.
A native Windows Runtime type must be defined in a DLL in order to be activatable (this effectively means “instantiable through Windows Runtime”). Your executable doesn’t need to go through Windows Runtime to instantiate types that it defines itself, but your unit test executable does need to go through Windows Runtime to instantiate those types.
I would suggest defining everything that you can in a DLL, and keeping your EXE as small as possible: have it just bootstrap your application, and put all of your real code in DLLs.