I need to run a test N times where the number N is supplied through an external file. So N is not compile time constant. How can I achieve this? I have tried implementing ITestAction and IFrameworkDriver like the following. When run a test in debug mode, the BeforeTest method is executed before the test runs and AfterTest after test is executed. I assumed Run method would be executed just to run the test, but it doesn't. Your help is appreciated.
[Extension]
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
public class CustomRunner : Attribute, ITestAction, IFrameworkDriver
{
private NUnit3FrameworkDriver frameworkDriver = new NUnit3FrameworkDriver(AppDomain.CurrentDomain);
#region ITestAction
public ActionTargets Targets => ActionTargets.Test;
public bool IsTestRunning => throw new NotImplementedException();
public void AfterTest(ITest test)
{
Console.WriteLine("After test is executed");
}
public void BeforeTest(ITest test)
{
Console.WriteLine("Before test is executed");
}
#endregion
public string Load(string testAssemblyPath, IDictionary<string, object> settings)
{
Console.WriteLine("Testting");
return frameworkDriver.Load(testAssemblyPath, settings);
}
public int CountTestCases(string filter)
{
Console.WriteLine("Testting");
return frameworkDriver.CountTestCases(filter);
}
public string Run(ITestEventListener listener, string filter)
{
Console.WriteLine("Testting");
return frameworkDriver.Run(listener, filter);
}
public string Explore(string filter)
{
Console.WriteLine("Testting");
return frameworkDriver.Explore(filter);
}
public void StopRun(bool force)
{
Console.WriteLine("Testting");
frameworkDriver.StopRun(force);
}
public string ID { get { return frameworkDriver.ID; } set { frameworkDriver.ID = value; } }
}
Test.cs
[TestFixture]
public class Test
{
[CustomRunner]
[Test]
public void JustATest()
{
Assert.True("a".Equals("a"));
}
}