How do I make Xunit test class and use constructor parameters like TestFixture with parameters in Nunit?
Asked Answered
H

1

6

In Nunit I can do something like this:

[TestFixture("param1")]
[TestFixture("param2")]
public class MyTestFixture
{
    public MyTestFixture(string param) { /* more code */ }
    /* more code */
}

After that all the tests and test cases inside class MyTestFixture will run twice, using parameters from TestFixture attributes one by one. Xunit doesn't use attribute TestFixture, so how can I do similar thing without specifying those two parameters in each test inside InlineData? If I do, it doubles the amount of attributes in my test code. I can write constructor with parameters, but I didn't find the way to pass data there. How do I do that?

Hix answered 28/11, 2019 at 20:45 Comment(0)
V
6

Looks like the XUnit developers closed this issue and mentioned that they will not be adding in support for this back in 2015:

https://github.com/xunit/xunit/issues/352

A few users within the GitHub thread have posted their alternate solutions for working around the lack of support for parameterized TestFixtures, which may help resolve your issue.

Volny answered 28/11, 2019 at 21:0 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.