vendredi 20 novembre 2015

Separate multiple categorized tests

I have a lot of test cases, and they should work different, depending on their category.
Example:

    [Test]
    [Category("Category1")
    [Category("Category2")
    private void DoSomething1()
    {
        if(((System.Collections.ArrayList)TestContext.CurrentContext.Test.Properties["_CATEGORIES"]).Contains("Category2")
        {
        //Doing something specific by Category2
        }

        if(((System.Collections.ArrayList)TestContext.CurrentContext.Test.Properties["_CATEGORIES"]).Contains("Category1")
        {
        //Doing something specific by Category1
        }

    }

The problem is that when I start the test process from NUnit by picking Category2, then DoSomething1 should run only the Category2 specific case. Code duplication is not an option.

How could I do that?

Aucun commentaire:

Enregistrer un commentaire