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

Class with multiple tests using MockedVSCollection and GlobalServiceProvider don't run all on VS #22

Open
dominoFire opened this issue Mar 15, 2022 · 1 comment

Comments

@dominoFire
Copy link

In a test project in VS, If I 'Run All' Tests from the class in VS, there are some random failing tests with the following message:

image

Message: 
    System.AggregateException : One or more errors occurred.
    ---- System.InvalidOperationException : Cannot create more than one System.Windows.Application instance in the same AppDomain.
    ---- The following constructor parameters did not have matching fixture data: GlobalServiceProvider gsp

  Stack Trace: 
    ----- Inner Stack Trace #1 (System.InvalidOperationException) -----
    Application.ctor()
    OleServiceProviderMock.MainThread()
    --- End of stack trace from previous location where exception was thrown ---
    TaskAwaiter.ThrowForNonSuccess(Task task)
    TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
    OleServiceProviderMock.ctor()
    GlobalServiceProvider.ctor()
    ----- Inner Stack Trace #2 (Xunit.Sdk.TestClassException) -----

Code

Test class

using Microsoft.VisualStudio.Sdk.TestFramework;
using Xunit;

namespace LibForVsSdk.Tests
{
    [Collection("LibForVsSdk.Tests.Test")]
    public class UnitTest1
    {
        public UnitTest1(GlobalServiceProvider gsp)
        {
        }

        [Fact]
        public void TestFalse()
        {
            Assert.False(false);
        }

        [Fact]
        public void TestTrue()
        {
            Assert.True(true);
        }

        [Theory]
        [InlineData(1)]
        [InlineData(2)]
        [InlineData(3)]
        public void Test1(int number)
        {
            Assert.True(number < 10);
        }
    }
}

Collection definition

using Microsoft.VisualStudio.Sdk.TestFramework;
using Xunit;

namespace LibForVsSdk.Tests
{
    [CollectionDefinition("LibForVsSdk.Tests.Test")]
    public class CollectionDef : ICollectionFixture<GlobalServiceProvider>
    {
    }
}

Test Project file

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>net472</TargetFramework>
    <Nullable>enable</Nullable>
	  <LangVersion>latest</LangVersion>
    <IsPackable>false</IsPackable>
  </PropertyGroup>

  <ItemGroup>
	  <PackageReference Include="Microsoft.VisualStudio.Sdk.TestFramework" Version="17.0.15" />
	  <PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.11.0" />
    <PackageReference Include="xunit" Version="2.4.1" />
    <PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
      <PrivateAssets>all</PrivateAssets>
    </PackageReference>
    <PackageReference Include="coverlet.collector" Version="3.1.0">
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
      <PrivateAssets>all</PrivateAssets>
    </PackageReference>
  </ItemGroup>

</Project>

Am I doing something wrong?

@nkolev92
Copy link
Member

nkolev92 commented Mar 17, 2022

Hitting the same issue, but in the opposite way.

Running tests in VS works, on the commandline/CI it doesn't :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants