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

Lifetime problem with Xunit: InvalidOperationException: There is no currently active test. #692

Open
StefanBertels opened this issue Jan 13, 2025 · 0 comments

Comments

@StefanBertels
Copy link

I get reproducable runtime error on one of two tests if I run all tests of the following test class / project. If I run just one test (e.g. manually in IDE Rider) everything looks good (no error).

Just guessing: maybe related to #657

Exception

System.InvalidOperationException: There is no currently active test.

System.InvalidOperationException
There is no currently active test.
   at Xunit.Sdk.TestOutputHelper.GuardInitialized() in /_/src/xunit.execution/Sdk/Frameworks/TestOutputHelper.cs:line 52
   at Xunit.Sdk.TestOutputHelper.QueueTestOutput(String output) in /_/src/xunit.execution/Sdk/Frameworks/TestOutputHelper.cs:line 61
   at Xunit.Sdk.TestOutputHelper.WriteLine(String message) in /_/src/xunit.execution/Sdk/Frameworks/TestOutputHelper.cs:line 109
   at TestProject1.UnitTest1.Test2() in TestProject1\UnitTest1.cs:line 18
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
   at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr)

Here is my C# project:

UnitTest1.cs

public class UnitTest1(Xunit.Abstractions.ITestOutputHelper testOutputHelper)
{
    [FsCheck.Xunit.Property]
    public void Test1()
    {
        testOutputHelper.WriteLine($"{nameof(Test1)}");
    }

    [Xunit.Fact]
    public void Test2()
    {
        testOutputHelper.WriteLine($"{nameof(Test2)}");
    }
}

TestProject1.csproj

<Project Sdk="Microsoft.NET.Sdk">
    <PropertyGroup>
        <TargetFramework>net8.0</TargetFramework>
        <IsTestProject>true</IsTestProject>
    </PropertyGroup>
    <ItemGroup>
        <PackageReference Include="FsCheck.Xunit" Version="3.0.0" />
        <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
        <PackageReference Include="xunit" Version="2.9.3" />
        <PackageReference Include="xunit.runner.visualstudio" Version="3.0.1" />
    </ItemGroup>
</Project>

Reproducable by just running dotnet test in project folder.

No error if I downgrade to xunit 2.8.1 / FsCheck.Xunit 2.16.6.

<Project Sdk="Microsoft.NET.Sdk">
    <PropertyGroup>
        <TargetFramework>net8.0</TargetFramework>
        <IsTestProject>true</IsTestProject>
    </PropertyGroup>
    <ItemGroup>
        <PackageReference Include="FsCheck.Xunit" Version="2.16.6" />
        <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
        <PackageReference Include="xunit" Version="2.8.1" />
        <PackageReference Include="xunit.runner.visualstudio" Version="3.0.1" />
    </ItemGroup>
</Project>
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

1 participant