mardi 30 mars 2021

Read TestFixture parameters from derived class in base class in NUnit

I have problem in which I do not know how to read the TestFixture Parameters in my TestBase class given in my derived Test class.

The way I want to structure my test cases is by having many derived test classes which inherits from a base class. There are some logic I need to do in the base class which will apply to all my derived classes.

Base class

public abstract class TestBase
{
    [Test]
    public async Task ExecuteTestCaseAsync(string parameter1, string parameter2)
    {    
         // Some logic handling the parameters
                    
         await this.RunAsync();
            
         // Clean up
    }
        
    protected abstract Task RunAsync();
}

A derived class

    [TestFixture("parameter1", "parameter2")]
    public class Test1 : TestBase
    {
        protected override async Task RunAsync()
        {
            // Some logic
        }
    }

Is there a way to do that in NUnit?

Aucun commentaire:

Enregistrer un commentaire