Search code examples
testingnunitvisual-studio-2013system-testing

NUnit - Multiple properties of the same name? Linking to requirements


I'm linking all our our System Tests to test cases and to our Requirements. Every requirement has an ID. Every Test Case / System Tests tests a variety of requirements. Every module of code links to multiple requirements.

I'm trying to find the best way to link every system test to its driving requirements.

I was hoping to do something like:

    [NUnit.Framework.Property("Release", "6.0.0")]
    [NUnit.Framework.Property("Requirement", "FR50082")]
    [NUnit.Framework.Property("Requirement", "FR50084")]
    [NUnit.Framework.Property("Requirement", "FR50085")]
    [TestCase(....)]
    public void TestSomething(string a, string b...)

However, that will break because Property is a Key-Value pair. The system will not allow me to have multiple Properties with the same key.

The reason I'm wanting this is to be able to test specific requirements in our system if a module changes that touches these requirements.

Rather than run over 1,000 system tests on every build, this would allow us to target what to test based on changes done to our code.

Some system tests run upwards of 5 minutes (Enterprise healthcare system), so "Just run all of them" isn't a viable solution. We do that, but only before promoting through our environments.

Thoughts?


Solution

  • Have you considered a custom property attribute derived from NUnit.Framework.Property?

    Something like the following seems like it might work for you judging by a LINQPad 4 "query" with Language set to C# Program and a reference to nunit.framework.dll (version 2.4.8) added:

    // main method to exercise a our PoC test case
    void Main()
    {
        TestSomething("a", "b");
    }
    
    // our PoC custom property attribute
    [AttributeUsage(AttributeTargets.Method, AllowMultiple=false)]
    public class RequirementsAttribute : NUnit.Framework.PropertyAttribute
    {
        public RequirementsAttribute(string[] requirements)
            : base(requirements)
        {
        }
    }
    
    // a test case using our custom property attribute to relate it to multiple requirements
    [Requirements(new string[] { "FR50082", "FR50084" })]
    [TestCase("PoCTest")]
    public void TestSomething(string a, string b)
    {
        // blah, blah, blah
    
        Assert.AreNotEqual(a, b);
    }