xUnit Testing in Testing Explorer

6 days ago 10
ARTICLE AD BOX

I'm trying to add tests to my MAUI app.
I added the xUnit test project to a separate namespace. The tests only run in the terminal with the dotnet test command.
If I use the test explorer, it doesn't find the tests and the launch fails. My project is .NET 9.0, but the VSTest Adapter runs (64-bit .NET Framework 4.8.9310.0).
The example of the log:

Построение тестовых проектов Запуск обнаружения тестов для запрошенного тестового запуска ========== Запуск обнаружения тестов ========== [xUnit.net 00:00:00.00] xUnit.net VSTest Adapter v3.1.5+1b188a7b0a (64-bit .NET Framework 4.8.9310.0) [xUnit.net 00:00:00.52] Exception discovering tests: System.IO.FileNotFoundException: Не удалось загрузить файл или сборку "System.Runtime, Version=9.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" либо одну из их зависимостей. Не удается найти указанный файл. Имя файла: 'System.Runtime, Version=9.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' в System.ModuleHandle.ResolveMethod(RuntimeModule module, Int32 methodToken, IntPtr* typeInstArgs, Int32 typeInstCount, IntPtr* methodInstArgs, Int32 methodInstCount) в System.ModuleHandle.ResolveMethodHandleInternalCore(RuntimeModule module, Int32 methodToken, IntPtr[] typeInstantiationContext, Int32 typeInstCount, IntPtr[] methodInstantiationContext, Int32 methodInstCount) в System.ModuleHandle.ResolveMethodHandleInternal(RuntimeModule module, Int32 methodToken, RuntimeTypeHandle[] typeInstantiationContext, RuntimeTypeHandle[] methodInstantiationContext) в System.Reflection.CustomAttributeData..ctor(RuntimeModule scope, CustomAttributeRecord caRecord) в System.Reflection.CustomAttributeData.GetCustomAttributes(RuntimeModule module, Int32 tkTarget) в System.Reflection.CustomAttributeData.GetCustomAttributesInternal(RuntimeAssembly target) в Xunit.Sdk.ReflectionAssemblyInfo.GetCustomAttributes(String assemblyQualifiedAttributeTypeName) в /_/src/xunit.execution/Sdk/Reflection/ReflectionAssemblyInfo.cs:строка 60 в Xunit.Sdk.XunitTestFrameworkDiscoverer..ctor(IAssemblyInfo assemblyInfo, ISourceInformationProvider sourceProvider, IMessageSink diagnosticMessageSink, IXunitTestCollectionFactory collectionFactory) в /_/src/xunit.execution/Sdk/Frameworks/XunitTestFrameworkDiscoverer.cs:строка 36 в Xunit.Sdk.XunitTestFramework.CreateDiscoverer(IAssemblyInfo assemblyInfo) в /_/src/xunit.execution/Sdk/Frameworks/XunitTestFramework.cs:строка 21 в Xunit.Sdk.TestFramework.GetDiscoverer(IAssemblyInfo assemblyInfo) в /_/src/xunit.execution/Sdk/Frameworks/TestFramework.cs:строка 71 в Xunit.Runner.v2.Xunit2..ctor(IMessageSink diagnosticMessageSink, AppDomainSupport appDomainSupport, ISourceInformationProvider sourceInformationProvider, IAssemblyInfo assemblyInfo, String assemblyFileName, String xunitExecutionAssemblyPath, String configFileName, Boolean shadowCopy, String shadowCopyFolder, Boolean verifyAssembliesOnDisk) в Xunit.Runner.v2.Xunit2.ForDiscoveryAndExecution(XunitProjectAssembly projectAssembly, ISourceInformationProvider sourceInformationProvider, IMessageSink diagnosticMessageSink, Boolean verifyAssembliesOnDisk) в Xunit.XunitFrontController.Create(XunitProjectAssembly projectAssembly, ISourceInformationProvider sourceInformationProvider, IMessageSink diagnosticMessageSink, ITestProcessLauncher testProcessLauncher) в Xunit.Runner.VisualStudio.VsTestRunner.<DiscoverTests>d__24`1.MoveNext() --- Конец трассировка стека из предыдущего расположения, где возникло исключение --- в System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() в Xunit.Runner.VisualStudio.VsTestRunner.<DiscoverTests>d__24`1.MoveNext() In MobileApp\tets\MA.Tests\bin\Debug\net9.0\MA.Tests.dll нет доступных тестов. Убедитесь, что средства обнаружения и выполнения тестов зарегистрированы, а также проверьте правильность параметров платформы и версии платформы, после чего повторите попытку. ========== Обнаружение тестов завершено: обнаружено тестов в 2,2 с: 0 ========== Выполняются все тесты в проекте: MA.Tests ========== Начало тестового запуска ========== ========== Запуск тестов прерван: тестов запущено в < 1 мс: 0 (пройдено: 0, не пройдено: 0, пропущено: 0). ==========

I tried clearing the cache, deleting the bin obj, and reinstalling the .NET 9.0 SDK. My .csproj looks like this:

<Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <TargetFramework>net9.0</TargetFramework> <ImplicitUsings>enable</ImplicitUsings> <Nullable>enable</Nullable> <IsPackable>false</IsPackable> <UseMaui>true</UseMaui> <GenerateAssemblyInfo>false</GenerateAssemblyInfo> <GenerateTargetFrameworkAttribute>false</GenerateTargetFrameworkAttribute> <OutputType>Exe</OutputType> </PropertyGroup> <ItemGroup> <PackageReference Include="coverlet.collector" Version="6.0.4"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> </PackageReference> <PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.0.1" /> <PackageReference Include="xunit" Version="2.9.3" /> <PackageReference Include="xunit.runner.visualstudio" Version="3.1.5"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> </PackageReference> </ItemGroup> <ItemGroup> <ProjectReference Include="..\..\src\MA\MA.csproj" /> </ItemGroup> <!--<PropertyGroup> <UseMicrosoftTestingPlatformRunner>true</UseMicrosoftTestingPlatformRunner> </PropertyGroup> <PropertyGroup> <DisableTestingPlatformServerCapability>true</DisableTestingPlatformServerCapability> </PropertyGroup>--> <ItemGroup> <Using Include="Xunit" /> </ItemGroup> </Project>

I also tried to use parts of the code, that now are commented. I added OutputType = exe, without that it didn't work either.

Is somebody has the same issue?

Read Entire Article