Tuesday, May 23, 2017

"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.

"Productivity power tools" allowed for the pretty paste from visual studio


    // 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 { }
 
    [TestFixtureUnitTestCoreTest]
    public class SomeClassTests
    {
        // This test has categories TestFixture, UnitTest, CoreTest
        [TestCoreTest]
        public void ShouldDoSomething()
        {
        }
    }