Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run TestFixture multiple times using Nunit or Jenkins

I have a TestFixture which contains multiple tests. I want to run this TestFixture multiple times to collect some statistics but can't seem to find a reasonable way. The RepeatAttribute cannot be used on a TestFixture.

I can use Nunit or Jenkins (with nunit plugin). Any ideas? Otherwise I would end up coding it into the test or use weird batch scripting.

like image 530
schwarz Avatar asked Nov 02 '25 06:11

schwarz


1 Answers

As Steve says, a parameterized fixture works, but if you want to run your test hundreds of times, it would get fairly tedious to copy and paste that many attributes.

A better option in NUnit is to use the TestFixtureSource attribute on your fixture. For example, the following code will run your test fixture 100 times;

[TestFixtureSource("TestData")]
public class MultipleRunFixture
{
    int _counter;

    public MultipleRunFixture(int counter)
    {
        _counter = counter;
    }

    public static IEnumerable<int> TestData =>
        Enumerable.Range(0, 100);

    [Test]
    public void TestMethod()
    {
        // TODO: Add your test code here
        Assert.Pass($"Test run {_counter}");
    }
}
like image 119
Rob Prouse Avatar answered Nov 04 '25 18:11

Rob Prouse



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!