Skip to content

Test run aborted when there are duplicate trait attributes #358

Closed

Description

Description

No helpful information to users when tests have duplicate trait attributes

Steps to reproduce

  1. dotnet new -t xunittest
  2. change the content of Tests.cs to the following
using System;
using System.Collections.Generic;
using System.Linq;
using Xunit;
using Xunit.Abstractions;
using Xunit.Sdk;

namespace Tests
{
    [Category(TestCategory.Async)]
    public class Tests
    {
        [Fact]
        [Category(TestCategory.Async)]
        public void Test1()
        {
            Assert.True(true);
        }
    }

    public enum TestCategory
    {
        Unspecified = 0,
        Async,
    }

    [TraitDiscoverer("Tests.CategoryDiscoverer", "xunittest")]
    [AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, AllowMultiple = true)]
    public class CategoryAttribute : Attribute, ITraitAttribute
    {
        public CategoryAttribute(TestCategory category)
        {
        }
    }

    public class CategoryDiscoverer : ITraitDiscoverer
    {
        public IEnumerable<KeyValuePair<string, string>> GetTraits(IAttributeInfo traitAttribute)
        {
            var args = traitAttribute.GetConstructorArguments().ToList();

            yield return new KeyValuePair<string, string>(args[0].ToString(), string.Empty);
        }
    }
}
  1. dotnet restore
  2. dotnet test

Expected behavior

Warning about duplicate attributes, but test should run

Actual behavior

Starting test execution, please wait...
Error: The active Test Run was aborted.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions