visualstudio.xunit icon indicating copy to clipboard operation
visualstudio.xunit copied to clipboard

Custom Trait-Attribute causes non-stop Discovery of Test-Methods in VS 2019

Open lanluu opened this issue 6 years ago • 7 comments

Hi,

in VS 2019 I am suffering a situation in that the discovery of xUnit Test-Methods in Test-Explorer (i.e. testhost process) runs endless, if any Test-Method has Custom-Trait-Attribute i.e. by adding any class inhered from ITraitAttribute and ITraitDiscoverer, for instance: https://github.com/xunit/samples.xunit/tree/master/TraitExtensibility

I would appreciate any idea in this case.

Thanks and best regards!

lanluu avatar Oct 07 '19 08:10 lanluu

As I figured out, this situation can caused in case the Custom-Trait-Attribute throws any Exception in Constructor e.g. because of validation of input params. For instance:

    [TraitDiscoverer("...", "...")]
    [AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
    public class ClassificationAttribute : Attribute, ITraitAttribute
    {
        public ClassificationAttribute(params Type[] traits)
        {
            // if you throw any Exception here because of invalid parameters,
            // and any Test-Method has this Attribute with invalid parameters,
            // then testhost process (in Test-Explorer) will run endless.
        }
    }

I hope it might help someones.

lanluu avatar Oct 07 '19 09:10 lanluu

Does this only fail in Visual Studio? If so, this issue needs to be moved to the right repo.

bradwilson avatar Oct 07 '19 15:10 bradwilson

Yes, only in Visual Studio. To which Repo should I move this thread?

lanluu avatar Oct 08 '19 14:10 lanluu

I'll move it. :)

bradwilson avatar Oct 08 '19 17:10 bradwilson

Same problem in Visual Studio 2022 when you use package SkippableFact for Xunit. It causes non-stop discovery like 33% of the time.

djalan avatar Apr 10 '24 16:04 djalan

Same problem in Visual Studio 2022 when you use package SkippableFact for Xunit. It causes non-stop discovery like 33% of the time.

I tested in a separate project and it seems fine.

BUT.

It is surely because my problematic project has its own class implementing XunitTestFramework. But the problem does not happen all the time.

djalan avatar Apr 10 '24 22:04 djalan

@djalan If you can provide a repro project that would be very helpful. Thanks!

bradwilson avatar Apr 14 '24 17:04 bradwilson