DEV Community

Russ Hammett
Russ Hammett

Posted on • Originally published at kritner.blogspot.com on

"non string" category NUnit tests

Didn't feel very "clean" about [Category("MyCategory")] peppered throughout the code base. This makes me feel a little better, though I wish I could easily apply the category attribute to an entire assembly.

    // Haven't figured out how to apply to assembly correctly, but added it as a flag in my base anyway
    [AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Class | AttributeTargets.Method)]
    public class BaseCategoryAttribute : CategoryAttribute { }

    public class FastIntegrationTestAttribute : BaseCategoryAttribute { }
    public class LongRunningIntegrationTestAttribute : BaseCategoryAttribute { }
    public class UnitTestAttribute : BaseCategoryAttribute { }
    public class CoreTestAttribute : BaseCategoryAttribute { }

    [TestFixture, UnitTest]
    public class SomeClassTests
    {
        // This test has categories UnitTest, CoreTest
        [Test, CoreTest]
        public void ShouldDoSomething()
        {
        }
    }

Discussion (1)

Collapse
kritner profile image
Russ Hammett Author

Pretty paste seemingly did not translate super well to dev.to :joy: