Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unit tests on a C#/WinRT projection does not start #1047

Closed
nseveno opened this issue Nov 16, 2021 · 4 comments
Closed

Unit tests on a C#/WinRT projection does not start #1047

nseveno opened this issue Nov 16, 2021 · 4 comments
Assignees
Labels
bug Something isn't working

Comments

@nseveno
Copy link

nseveno commented Nov 16, 2021

Describe the bug
I have a solution with some C++/WinRT components that perform audio processing.
I created a C#/WinRT projection for theses components.
My graphical interface (C# / WinUI 3) uses this projection. It works great.

I would like to be able to unit test my C++/WinRT components in a C# MS Test project. (As my GUI is in C#, I would like to be able to write theses tests in C#).
So I created a C# MS Test project. I referenced the projection project.
When I launch a unit test, it never starts. Instead, a "file not found" error appears in the "Tests" output.

I already filed a bug on the developercommunity.visualstudio.com website.
But without success. Maybe it was in the wrong team ?
I'm stuck in my project, with a lot of C++ code, and I'm not able to test it. Very frustrating...

Mabe someone here could give me a workaround ?

To Reproduce
I created a minimal repro project.
ReproUnitTestProjection.zip

Just open the solution in the Zip.
Select Debug|x64 for the current configuration / platform
Rebuild the solution
Open the tests explorer
In the “ViewModelTests” class, try to run the “SayHelloTest” unit test => Nothing happens
In the output window, select the “Tests” output => You should see the following error message :

Les tests à exécuter sont introuvables.
Magasin de données de test ouvert en 0,006 s.
Démarrage de la découverte de tests
[MSTest][Discovery][C:\Users\***\source\repos\ReproUnitTestProjection\ReproUnitTestProjection.Component.Tests\bin\x64\Debug\net5.0-windows10.0.19041\ReproUnitTestProjection.Component.Tests.dll] Échec de la découverte de tests à partir de l'assembly C:\Users\***\source\repos\ReproUnitTestProjection\ReproUnitTestProjection.Component.Tests\bin\x64\Debug\net5.0-windows10.0.19041\ReproUnitTestProjection.Component.Tests.dll. Raison :Fichier inexistant : C:\Users\***\source\repos\ReproUnitTestProjection\ReproUnitTestProjection.Component.Tests\bin\x64\Debug\net5.0-windows10.0.19041\ReproUnitTestProjection.Component.Tests.dll
Aucun test n'est disponible dans C:\Users\***\source\repos\ReproUnitTestProjection\ReproUnitTestProjection.Component.Tests\bin\x64\Debug\net5.0-windows10.0.19041\ReproUnitTestProjection.Component.Tests.dll. Vérifiez que les découvreurs et exécuteurs de tests sont inscrits. Vérifiez également que les paramètres de version de plateforme et de framework sont appropriés, puis réessayez.
========== Fin de la découverte de tests : 0 tests trouvés en 677,7 ms ==========

Expected behavior
The unit tests should run.

Version Info
Visual Studio 2022 current version
C++/WinRT last version
Microsoft.Windows.CsWinRT version 1.3.5
(WinUI 3 version 1.0.0-preview3)

Additional context

@nseveno nseveno added the bug Something isn't working label Nov 16, 2021
@angelazhangmsft angelazhangmsft self-assigned this Dec 7, 2021
@angelazhangmsft
Copy link
Contributor

angelazhangmsft commented Dec 7, 2021

@nseveno - I took a look at the repro, and the issue is that the test project is not using a packaged app. Currently unpackaged C#/WinRT apps are not working with MSTest. Here is an example of a packaged app using MSTest (note the package manifest, and the use of <EnablePreviewMsixTooling>. We will need to investigate the unpackaged scenario.

@Scottj1s
Copy link
Member

Scottj1s commented Dec 7, 2021

There's no reason MSTest cannot execute unpackaged C#/WinRT projection code. This is a regression in MSTest, which was introduced with the WinUI support. That support is triggered via a specific test method attribute, UITestMethod. But independently, the test project's TFM also determines the test adapter to copy from the nuget. E.g., a value of net5.0-windows10.0.19041 copies the PlatformServices.WinUI adapter from "%NUGET_PACKAGES%\mstest.testadapter\2.2.5\build\net5.0-windows10.0.18362.0\Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.dll". The problem is that the WinUI test adapter assumes packaged execution in calls [like this]:(https://github.com/microsoft/testfx/blob/19acefa11712c387774784a79dafcf7b3dbee64c/src/Adapter/PlatformServices.WinUI/Services/WinUIFileOperations.cs#L109):

        public string GetFullFilePath(string assemblyFileName)
        {
            return (SafeInvoke<string>(() => Path.Combine(Windows.ApplicationModel.Package.Current.InstalledLocation.Path, assemblyFileName)) as string) ?? assemblyFileName;
        }

The test code here is not using WinUI, so it could just rely on the PlatformService.Desktop adapter code, but the TFM behavior above doesn't support that. You can back off to an earlier version of MSTest (I verified that 2.23 works) and you could also enter a bug in the MSTest repo to support unpackaged:
https://github.com/microsoft/testfx

@nseveno
Copy link
Author

nseveno commented Dec 8, 2021

Thanks for answering.

Downgrading to 2.2.3 works ! For reference, I just had to change the nuget references, rebuild and reopen the solution.

I think this existing bug in the MSTest repo should fix the problem.

Since the problem will be solved by the MSTest team, I close this bug.

@nseveno
Copy link
Author

nseveno commented Apr 29, 2022

This problem is solved in MSTest nugets version 2.2.10.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants