DEV Community

Russ Hammett
Russ Hammett

Posted on • Originally published at 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()

Top comments (1)

kritner profile image
Russ Hammett

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