thomhurst / TUnit

A modern, fast and flexible .NET testing framework
MIT License
2.31k stars 37 forks source link

[BUG]: `[NotInParallel]` breaks `[DependsOn]` #1176

Closed viceroypenguin closed 1 day ago

viceroypenguin commented 3 days ago

Check the following code:

[NotInParallel]
public sealed class Dummy
{
    [Test]
    public void Step1()
    {
        throw new NotImplementedException();
    }

    [Test]
    [DependsOn(nameof(Step1))]
    public void Step2()
    {

    }

    [Test]
    [DependsOn(nameof(Step2))]
    public void Step3()
    {

    }
}

Expected: Step2 will fail since Step1 did not succeeed.

Actual: Step2 passes, but Step3 fails because Step1 has failed.

thomhurst commented 3 days ago

Struggling to recreate with your code. Must be some race condition or something 🤔

image

viceroypenguin commented 3 days ago

Try:

public class BaseClass;

[ClassConstructor<DummyClassConstructor>]
[NotInParallel]
public sealed class Dummy : BaseClass
{
    [Test]
    public void Step1()
    {
        throw new NotImplementedException();
    }

    [Test]
    [DependsOn(nameof(Step1))]
    public void Step2()
    {

    }

    [Test]
    [DependsOn(nameof(Step2))]
    public void Step3()
    {

    }
}

public class DummyClassConstructor : IClassConstructor
{
    public T Create<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] T>(ClassConstructorMetadata classConstructorMetadata) where T : class
    {
        if (typeof(T) != typeof(Dummy))
            throw new NotImplementedException();
        return (T)(object)new Dummy();
    }
}

image

thomhurst commented 3 days ago

Still the same for me! Can you confirm it still happens on 0.2.202?

viceroypenguin commented 3 days ago

I would, except now VS cannot run the tests; either it spends 2+ minutes trying to find tests before I cancel it, or it runs Step1/Step2 and never completes either of them. I can confirm that running the project under 0.2.195 gave me two fails and one pass, while 0.2.202 gives me three fails, as expected.

thomhurst commented 2 days ago

The latest version has broken Visual Studio for you?

viceroypenguin commented 2 days ago

The latest version has broken Visual Studio for you?

Yes. Was fine under 0.2.195, broken on 0.2.202

thomhurst commented 1 day ago

@viceroypenguin Can you reproduce it? My test explorer is working fine on the latest version.

viceroypenguin commented 1 day ago

Yes. This is what happens currently in VS 17.12 preview 5: image

viceroypenguin commented 1 day ago

image

thomhurst commented 1 day ago

Can you try 0.2.208?

viceroypenguin commented 1 day ago

Yes, 0.2.208 works correctly. Thanks!