Search code examples
unit-testingmstestuwp

Running Universal Windows unit tests from the command line


How do you run Universal Windows (UWP) unit test projects from the command line?

I am using the MSTestFramework.


Solution

  • Short answer:

    vstest.console.exe /Platform:x64 AppPackages\UnitTestProject1_1.0.0.0_x64_Debug_Test\UnitTestProject1_1.0.0.0_x64_Debug.appx
    

    Long answer:

    1. Create the project by selecting Universal / Unit Test App (Universal Windows) template:

      enter image description here

    2. Build it with command line using in the folder where the solution file is

      msbuild /p:Platform=x64;Configuration=Debug

    3. Try running the vstest.console.exe command above, in the short answer. It will fail, giving the following error message:

      error 0x800B0109: The root certificate of the signature in the app package or bundle must be trusted..
      For more details look into Event Viewer under Applications and Services Logs -> Microsoft -> Windows -> AppXDeployment-Server -> Microsoft-Windows-AppXDeploymentServer/Operational.
      
    4. To be able to run tests from command line, you need to use a certificate which has trusted root, or make the certificate that generated by visual studio trusted. For the latter, double click UnitTestProject1_TemporaryKey.pfx file from windows explorer, and follow the import wizard default steps, but change two things:

      • Set Store Location to local machine: enter image description here
      • Place the certificate to Trusted Root Certification Authorities store: enter image description here
      • Finishing the wizard should say "The import was successful."
    5. Try running vstest.console.exe using the parameters in the short answer, and now it should run all your tests.